Skip to content

Commit

Permalink
Some Changes based on suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
palmer-matthew committed Sep 15, 2020
1 parent 318c935 commit d0919b3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 75 deletions.
55 changes: 13 additions & 42 deletions lib/models/from_postgres/scholarship/scholarship.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,20 @@ class Scholarship {
this.condition
});

//Getter Methods for the attributes
String get scholarshipName => name;
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['additional_details'] == "" ? details = null : details = parsedJSON['additional_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: name,
details: details,
numAwards: numAwards,
value: value,
tenure: tenure,
eligible: eligible,
criteria: criteria,
method: method,
special: special,
condition: condition,
);
//This constructor converts a json map into an Scholarship Object
Scholarship.fromJson( Map<String, dynamic> parsedJson){
parsedJson['name'] == "" ? name = null : name = parsedJson['name'];
parsedJson['additional_details'] == "" ? details = null : details = parsedJson['additional_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'];
}

//TODO: documentation @palmer-matthew
String buildListItem(String title, content, bool inList){

Expand Down
22 changes: 10 additions & 12 deletions lib/models/scholarship_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,33 @@ import 'package:flutter/foundation.dart';
class ScholarshipList with ChangeNotifier{

bool hasResults; // signifies if the search results has any data

List<Scholarship> scholarships; // original list of scholarships from http requests
List<Scholarship> current; // The current list which is used in the list view

ScholarshipList({scholarships}){
this.scholarships = scholarships;
hasResults = true;
current = this.scholarships;
}

//Getter Methods
List<Scholarship> get scholarList => current;
bool get doesHaveResults => hasResults;
bool get isSearching => current != scholarships;

//Factory Method for converting json into the model used
factory ScholarshipList.fromJson(List<dynamic> parsedJson) {
ScholarshipList({scholarships}){
this.scholarships = scholarships;
hasResults = true;
current = this.scholarships;
}

//Named Constructor for converting json into the model used
ScholarshipList.fromJson(List<dynamic> parsedJson) {
List<Scholarship> lst = new List<Scholarship>();
lst = parsedJson.map((i) => Scholarship.fromJson(i)).toList();
return new ScholarshipList(
scholarships: lst,
);
this.scholarships = lst;
}

//Function which searches to see if the query is contained in the Scholarship Name
//Possibly could be refined for better searching methods
void search(String query){

current = scholarships.where((p) => p.scholarshipName.toLowerCase().contains(query.toLowerCase())).toList();
current = scholarships.where((p) => p.name.toLowerCase().contains(query.toLowerCase())).toList();

if(current.isEmpty){
current = [Scholarship(name:"No Search Results")];
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/scholarship_screen/local_widget/scholar_card.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:fst_app_flutter/models/from_postgres/scholarship/scholarship.dart';
import 'package:fst_app_flutter/screens/scholarship_screen/scholarship_detailsview.dart';
import 'package:fst_app_flutter/screens/scholarship_screen/scholarship_details_view.dart';

///Widget used by [ScholarshipMobile] to display the elements of the lists from [ScholarshipList]
//TODO: documentation @palmer-matthew
Expand All @@ -17,7 +17,7 @@ class ScholarCard extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: ListTile(
title: Text(scholarship.scholarshipName),
title: Text(scholarship.name),
trailing: Icon(
Icons.arrow_forward_ios,
size: 18,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ScholarshipDetailsView extends StatelessWidget {
Widget _buildAppBar(){
return AppBar(
title: Text(
current.scholarshipName,
current.name,
),
actions: [
IconButton(
Expand Down Expand Up @@ -187,20 +187,20 @@ class ScholarshipDetailsView extends StatelessWidget {
List<Widget> result = List.empty(growable: true);
try{

if(current.scholarshipAwards != null){
result.addAll([buildListTile('Number of Awards', current.scholarshipAwards, false), buildDivider()]);
if(current.numAwards != null){
result.addAll([buildListTile('Number of Awards', current.numAwards, false), buildDivider()]);
}

if(current.scholarshipValue != null){
result.addAll([buildListTile('Value', current.scholarshipValue, false), buildDivider()]);
if(current.value != null){
result.addAll([buildListTile('Value', current.value, false), buildDivider()]);
}

if(current.scholarshipTenure != null){
result.addAll([buildListTile('Maximum Tenure', current.scholarshipTenure , false), buildDivider()]);
if(current.tenure != null){
result.addAll([buildListTile('Maximum Tenure', current.tenure , false), buildDivider()]);
}

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

}on Exception catch(e){
Expand All @@ -215,24 +215,24 @@ class ScholarshipDetailsView extends StatelessWidget {

try{

if(current.scholarshipCriteria != null){
result.addAll([buildListingTile("Criteria", current.scholarshipCriteria), buildDivider()]);
if(current.criteria != null){
result.addAll([buildListingTile("Criteria", current.criteria), buildDivider()]);
}

if(current.scholarshipMethod != null){
result.addAll([buildListingTile("Method Of Selection", current.scholarshipMethod), buildDivider()]);
if(current.method != null){
result.addAll([buildListingTile("Method Of Selection", current.method), buildDivider()]);
}

if(current.scholarshipSpecial != null){
result.addAll([buildListingTile("Special Requirements", current.scholarshipSpecial), buildDivider()]);
if(current.special != null){
result.addAll([buildListingTile("Special Requirements", current.special), buildDivider()]);
}

if(current.scholarshipCondition != null){
result.addAll([buildListingTile("Condition", current.scholarshipCondition), buildDivider()]);
if(current.condition != null){
result.addAll([buildListingTile("Condition", current.condition), buildDivider()]);
}

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

}on Exception catch(e){
Expand Down

0 comments on commit d0919b3

Please sign in to comment.