Skip to content

Commit

Permalink
Added Copying to Clipboard Feature, Details to Add
Browse files Browse the repository at this point in the history
  • Loading branch information
palmer-matthew committed Sep 6, 2020
1 parent 9c5afd9 commit 585ad2b
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 4 deletions.
130 changes: 130 additions & 0 deletions lib/models/from_postgres/scholarship/scholarship.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,134 @@ class Scholarship {
condition: condition,
);
}

String buildListItem(String title, content, bool inList){

if(content == "" && inList){
return "\u2022 $title\n";
}

return "- $title \n $content\n";
}

String buildHeading(title, content){
List<String> secondary;
String result = "";
try {
if(content.contains(":")){
List<String> list = content.split(":");
if(list[1].contains(";") && list.length == 2){
secondary = list[1].split(";");
String slist = "";
for(String b in secondary){
if(b != ""){
slist += buildListItem(b, "", true);
}
}
result += buildListItem(title, list[0]+":", false);
result += slist;
return result;
}else if(list[1].contains(";") && list.length == 3){
secondary = list[1].split(";");
String slist = "";
result += buildListItem(title, "" , false);
result += "\t" + buildListItem(list[0], "", true);
for(String b in secondary){
if(b != ""){
slist += "\t\t" + buildListItem(b, "", true);
}
}
result += slist;
result += "\t" + buildListItem(list[2], "", true);
return result;
}else if(list.length == 2 && !list[1].contains(";")){
result += buildListItem(title, list[0]+":", false);
result += "\t" + buildListItem(list[1], "", true);
return result;
}else {
return buildListItem(title, list[1], false);
}
}else if(content.contains(";")){
List<String> list = content.split(";");
String slist = "";
for(String b in list){
if(b != ""){
slist += "\t" + buildListItem(b, "", true);
}
}
result += buildListItem(title, "", false);
result += slist;
return result;
}else{
return buildListItem(title, content, false);
}
} on Exception catch (e) {
print(e);
return "Something went wrong";
}

}

String buildDescriptionContent(){
String result = "";
try{

if(numAwards != null){
result += buildHeading('Number of Awards', numAwards) + "_____________________\n\n";
}

if(value != null){
result += buildHeading('Value', value) + "_____________________\n\n";
}

if(tenure != null){
result += buildHeading('Maximum Tenure', tenure) + "_____________________\n\n";
}

if(eligible != null){
result += buildHeading("Eligibility", eligible) + "_____________________\n\n";
}

}on Exception catch(e){
print(e);
result = "Something went wrong";
}
return result;
}

String buildDetailContent(){
String result = "";
try{

if(criteria != null){
result += buildHeading("Criteria", criteria) + "_____________________\n\n";
}

if(method != null){
result += buildHeading("Method Of Selection", method) + "_____________________\n\n";
}

if(special != null){
result += buildHeading("Special Requirements", special) + "_____________________\n\n";
}

if(condition != null){
result += buildHeading("Condition", condition) + "_____________________\n\n";
}

if(details != null){
result += buildHeading("Additional Details", details) + "_____________________\n\n";
}

}on Exception catch(e){
print(e);
result = "Something went wrong";
}
return result;
}

@override
String toString() {
return "${name.toUpperCase()}\n\n" + buildDescriptionContent() + buildDetailContent();
}
}
28 changes: 24 additions & 4 deletions lib/screens/scholarship_screen/scholarship_detailsview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/scheduler.dart';
import 'package:provider/provider.dart';
import 'package:fst_app_flutter/models/preferences/theme_model.dart';
import 'package:fst_app_flutter/models/from_postgres/scholarship/scholarship.dart';
import 'package:clipboard/clipboard.dart';

class ScholarshipDetailsView extends StatelessWidget {

Expand All @@ -16,6 +17,15 @@ class ScholarshipDetailsView extends StatelessWidget {
title: Text(
current.scholarshipName,
),
actions: [
IconButton(
icon: Icon(Icons.content_copy),
onPressed: (){
FlutterClipboard.copy(current.toString()).then(( value ) => print('copied'));
},
tooltip: "Copy to Clipboard",
)
],
bottom: TabBar(
indicatorColor: Colors.white,
tabs: [
Expand Down Expand Up @@ -54,15 +64,24 @@ class ScholarshipDetailsView extends StatelessWidget {
return UnorderedListItem(title, theme['isDark']);
}else if(content is! String){
return ListTile(
title: Text(title),
title: SelectableText(
title,
toolbarOptions: ToolbarOptions(copy: true, selectAll: true,),
),
subtitle: content,
);
}

return ListTile(
visualDensity: VisualDensity(vertical: -2.0, horizontal: 1.0),
title: Text(title),
subtitle: Text(content),
title: SelectableText(
title,
toolbarOptions: ToolbarOptions(copy: true, selectAll: true,),
),
subtitle: SelectableText(
content,
toolbarOptions: ToolbarOptions(copy: true, selectAll: true,),
),
);
}

Expand Down Expand Up @@ -266,11 +285,12 @@ class UnorderedListItem extends StatelessWidget {
),
),
Expanded(
child: Text(
child: SelectableText(
text,
style: TextStyle(
color: isDark ? Colors.white54 : Colors.black45,
),
toolbarOptions: ToolbarOptions(copy: true, selectAll: true,),
),
),
],
Expand Down
2 changes: 2 additions & 0 deletions lib/screens/scholarship_screen/scholarship_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class _ScholarshipMobileState extends State<ScholarshipMobile> {
isSearching = false;
});
},
tooltip: "Stop Searching",
),
title: Theme(
data: Theme.of(context).copyWith(
Expand All @@ -74,6 +75,7 @@ class _ScholarshipMobileState extends State<ScholarshipMobile> {
symbol.search(_controller.text);
});
},
tooltip: "Clear Text",
),
]);
}
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
clipboard:
dependency: "direct main"
description:
name: clipboard
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2+8"
clock:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies:
provider: ^4.3.1
permission_handler: ^5.0.1+1
google_maps_flutter: ^0.5.30
clipboard: ^0.1.2+8
dev_dependencies:
flutter_test:
sdk: flutter
Expand Down

0 comments on commit 585ad2b

Please sign in to comment.