Skip to content

Commit

Permalink
Changed Details View, Server Call is Local, Some Design Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
palmer-matthew committed Sep 2, 2020
1 parent 022899f commit 398058c
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 64 deletions.
54 changes: 46 additions & 8 deletions lib/models/from_postgres/scholarship/scholarship.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,60 @@
class Scholarship {
//Attributes of the Class
String name;
String description;
String details;
String name, details, numAwards, tenure, value, eligible, criteria ,method , special, condition;

//Constructor for the Scholarship Class
Scholarship({this.name, this.description, this.details});
Scholarship({this.name,
this.details,
this.numAwards,
this.value,
this.tenure,
this.eligible,
this.criteria,
this.method,
this.special,
this.condition
});

//Getter Methods for the attributes
String get scholarshipName => name;
String get scholarshipDescription => description;
String get scholarshipDetails => details;
String get scholarshipAwards => numAwards;
String get scholarshipValue => value;
String get scholarshipTenure => tenure;
String get scholarshipCriteria => criteria;
String get scholarshipEligibility => eligible;
String get scholarshipMethod => method;
String get scholarshipSpecial => special;
String get scholarshipCondition => condition;

//This method converts a json map into an Scholarship Object
factory Scholarship.fromJson(Map<String, dynamic> parsedJSON) {

String name, details, numAwards, value, tenure, eligible, criteria ,method , special, condition;

parsedJSON['name'] == "" ? name = null : name = parsedJSON['name'];
parsedJSON['details'] == "" ? details = null : details = parsedJSON['details'];
parsedJSON['number_of_awards'] == "" ? numAwards = null : numAwards = parsedJSON['number_of_awards'];
parsedJSON['value'] == "" ? value = null : value = parsedJSON['value'];
parsedJSON['max_tenure'] == "" ? tenure = null : tenure = parsedJSON['max_tenure'];
parsedJSON['eligibility'] == "" ? eligible = null : eligible = parsedJSON['eligibility'];
parsedJSON['criteria'] == "" ? criteria = null : criteria = parsedJSON['criteria'];
parsedJSON['method_of_selection'] == "" ? method = null : method = parsedJSON['method_of_selection'];
parsedJSON['special_requirements'] == "" ? special = null : special = parsedJSON['special_requirements'];
parsedJSON['condition'] == "" ? condition = null : condition = parsedJSON['condition'];


return Scholarship(
name: parsedJSON['name'],
description: parsedJSON['description'],
details: parsedJSON['details']);
name: name,
details: details,
numAwards: numAwards,
value: value,
tenure: tenure,
eligible: eligible,
criteria: criteria,
method: method,
special: special,
condition: condition,
);
}
}
3 changes: 1 addition & 2 deletions lib/models/scholarshiplist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class ScholarshipList with ChangeNotifier{
ScholarshipList({scholarships}){
this.scholarships = scholarships;
hasResults = true;
current = this.scholarships.where((p) => p.scholarshipName.toLowerCase().contains("young".toLowerCase())).toList();
//current = this.scholarships;
current = this.scholarships;
}

//Getter Methods
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/scholarship_screen/scholarship_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class _ScholarshipDetailsState extends State<ScholarshipDetails> {
controller: _scroll,
children: <Widget>[
_buildSizedBox(mq*.025),
_buildCard("Description", widget.current.scholarshipDescription),
// _buildCard("Description", widget.current.scholarshipDescription),
_buildSizedBox(mq*.025),
_buildCard("Details", widget.current.scholarshipDetails),
_buildSizedBox(mq*.025),
Expand Down
205 changes: 166 additions & 39 deletions lib/screens/scholarship_screen/scholarship_detailsview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,67 +40,194 @@ class ScholarshipDetailsView extends StatelessWidget {
}

Widget _buildPage(String zone){
return ListView(
children: zone == "Description" ? parse(current.description) : parse(current.details),
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: ListView(
physics: AlwaysScrollableScrollPhysics(),
children: zone == "Description" ? buildDescriptionContent() : buildDetailContent(),
),
);
}

List<Widget> parse(String content){
Widget buildListTile(String title, content, bool inList){

if(content == "" && inList){
return ListTile(
// leading: Container(
// height: 5.0,
// width: 5.0,
// decoration: new BoxDecoration(
// color: Colors.grey.shade900,
// shape: BoxShape.circle,
// ),
// ),
title: Text(
"\u2022 " + title,
),
);
}else if(content is! String){
return ListTile(
title: Text(title),
subtitle: content,
contentPadding: const EdgeInsets.symmetric(vertical: 10),
);
}

return ListTile(
title: Text(title),
subtitle: Text(content),
contentPadding: const EdgeInsets.symmetric(vertical: 10),
);
}

Widget buildListingTile(title, content){
List<Widget> primaryWidget = List.empty(growable: true);
List<Widget> secondaryWidgets = List.empty(growable: true);
List<String> secondary;

List<String> catergory_split = content.split('@');
String titleContent;
String title;
String singleLine;
List<String> list;
List<Widget> result = List.empty(growable: true);
try {
for (String a in catergory_split){
List<String> titleSplit = a.split(":");
title = titleSplit[0];
titleContent = titleSplit[1];
if(titleContent.contains("=")){
list = titleContent.split("=");
singleLine = list[0];
List<String> listing = list[1].split(";");
List<Widget> listing_widget = List.empty(growable: true);
for(String b in listing){
listing_widget.add(ListTile(
leading: Icon(Icons.lens),
title: Text(
b,
style: TextStyle(
fontSize: 13,
),
),
));
if(content.contains(":")){
List<String> list = content.split(":");
if(list[1].contains(";") && list.length == 2){
secondary = list[1].split(";");
for(String b in secondary){
if(b != ""){
secondaryWidgets.add(buildListTile(b, "", true));
}
}
result.add(ListBody(
return ListBody(
children: [
ListTile(
title: Text(title),
subtitle: Text(singleLine),
),
buildListTile(title, list[0], false),
Padding(
padding: const EdgeInsets.only(left: 18.0),
child: ListBody(
children: listing_widget,
padding: const EdgeInsets.only(left: 10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: secondaryWidgets,
),
),
SizedBox(
height: 20,
),
],
));
);
}else if(list[1].contains(";") && list.length == 3){
secondary = list[1].split(";");
for(String b in secondary){
if(b != ""){
secondaryWidgets.add(buildListTile(b, "", true));
}
}
primaryWidget.add(buildListTile(title, "", false));
primaryWidget.add(
buildListTile(
list[0],
Padding(
padding: const EdgeInsets.only(left: 18.0),
child: ListBody(
children: secondaryWidgets,
),
),
false));
primaryWidget.add(buildListTile(list[2], "", false));
return ListBody(
children: primaryWidget,
);
}else{
result.add(ListTile(title: Text(title), subtitle: Text(titleContent),));
return buildListTile(title, list[1], false);
}
}else if(content.contains(";")){
List<String> list = content.split(";");
for(String b in list){
if(b != ""){
secondaryWidgets.add(buildListTile(b, "", true));
}
}
return ListBody(
children: [
buildListTile(title, "", false),
Padding(
padding: const EdgeInsets.only(left: 18.0),
child: ListBody(
children: secondaryWidgets,
),
),
SizedBox(
height: 20,
),
],
);
}else{
return buildListTile(title, content, false);
}
} on Exception catch (e) {
print(e);
result = <Widget>[Text('Something went wrong'),];
return Center(child: Text(title));
}

}

List<Widget> buildDescriptionContent(){
List<Widget> result = List.empty(growable: true);
try{

if(current.scholarshipAwards != null){
result.add(buildListTile('Number of Awards', current.scholarshipAwards, false));
}

if(current.scholarshipValue != null){
result.add(buildListTile('Value', current.scholarshipValue, false));
}

if(current.scholarshipTenure != null){
result.add(buildListTile('Maximum Tenure', current.scholarshipTenure , false));
}

if(current.scholarshipEligibility != null){
result.add(buildListingTile("Eligibility", current.scholarshipEligibility));
}

}on Exception catch(e){
print(e);
result = <Widget>[Center(child: Text("Something went wrong")),];
}
return result;
}

List<Widget> buildDetailContent(){
List<Widget> result = List.empty(growable: true);
//details, criteria, method, special, condition,
try{

if(current.scholarshipCriteria != null){
result.add(buildListingTile("Criteria", current.scholarshipCriteria));
}

if(current.scholarshipMethod != null){
result.add(buildListingTile("Method Of Selection", current.scholarshipMethod));
}

if(current.scholarshipSpecial != null){
result.add(buildListingTile("Special Requirements", current.scholarshipSpecial));
}

if(current.scholarshipCondition != null){
result.add(buildListingTile("Condition", current.scholarshipCondition));
}

if(current.scholarshipDetails != null){
result.add(buildListingTile("Additional Details", current.scholarshipDetails));
}

}on Exception catch(e){
print(e);
result = <Widget>[Center(child: Text("Something went wrong")),];
}
return result;
}


@override
Widget build(BuildContext context) {
ThemeModel themeModel = Provider.of<ThemeModel>(context, listen: false,);
Expand Down
21 changes: 8 additions & 13 deletions lib/screens/scholarship_screen/scholarship_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,14 @@ class _ScholarshipMobileState extends State<ScholarshipMobile> {
break;
case ConnectionState.done:
if (!snapshot.hasData || snapshot.hasError) {
// return Center(
// child: Text(
// "An Error Occurred",
// style: TextStyle(
// color: Colors.grey.shade400,
// fontSize: 18,
// ),
// ),
// );
return ListView(
children: [
ScholarCard(scholarship: Scholarship(name: "Jimmy Neutron Welfare Scholarship"),),
],
return Center(
child: Text(
"An Error Occurred",
style: TextStyle(
color: Colors.grey.shade400,
fontSize: 18,
),
),
);
} else {
return ChangeNotifierProvider(
Expand Down
2 changes: 1 addition & 1 deletion lib/services/scholarship_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ScholarshipService{
static Future<ScholarshipList> getAllScholarships() async {
try {
HerokuRequest<Scholarship> handler = HerokuRequest();
var result = await handler.getResults("scholarship/",true, (data) => Scholarship.fromJson(data));
var result = await handler.getResults("http:https://192.168.0.11:8000/scholarship/", false, (data) => Scholarship.fromJson(data));
return Future(() => ScholarshipList(scholarships: result));
} catch (e) {
throw Exception('Cannot load from server');
Expand Down

0 comments on commit 398058c

Please sign in to comment.