Skip to content

Commit

Permalink
Merge branch 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
richtwin567 committed Sep 15, 2020
2 parents 2f1e2bc + a5ba657 commit 385952b
Show file tree
Hide file tree
Showing 10 changed files with 693 additions and 396 deletions.
172 changes: 156 additions & 16 deletions lib/models/from_postgres/scholarship/scholarship.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,162 @@
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});

//Getter Methods for the attributes
String get scholarshipName => name;
String get scholarshipDescription => description;
String get scholarshipDetails => details;

//This method converts a json map into an Scholarship Object
factory Scholarship.fromJson(Map<String, dynamic> parsedJSON) {
return Scholarship(
name: parsedJSON['name'],
description: parsedJSON['description'],
details: parsedJSON['details']);
Scholarship({this.name,
this.details,
this.numAwards,
this.value,
this.tenure,
this.eligible,
this.criteria,
this.method,
this.special,
this.condition
});

//This constructor converts a json map into an Scholarship Object
Scholarship.fromJson(Map<String, dynamic> parsedJson){
name = parsedJson['name'];
details = parsedJson['additional_details'];
numAwards = parsedJson['number_of_awards'];
value = parsedJson['value'];
tenure = parsedJson['max_tenure'];
eligible = parsedJson['eligibility'];
criteria = parsedJson['criteria'];
method = parsedJson['method_of_selection'];
special = parsedJson['special_requirements'];
condition = parsedJson['condition'];
}

//TODO: documentation @palmer-matthew
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 != ""){
result += buildHeading('Number of Awards', numAwards) + "_____________________\n\n";
}

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

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

if(eligible != ""){
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 != ""){
result += buildHeading("Criteria", criteria) + "_____________________\n\n";
}

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

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

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

if(details != ""){
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();
}
}
87 changes: 6 additions & 81 deletions lib/models/scholarship_list.dart
Original file line number Diff line number Diff line change
@@ -1,116 +1,41 @@
import 'package:fst_app_flutter/models/from_postgres/scholarship/scholarship.dart';
import 'package:fst_app_flutter/utils/debouncer.dart';
import 'package:flutter/foundation.dart';

// Defines the model for the manager of the list of Scholarships
class ScholarshipList with ChangeNotifier{

bool isPerformingRequest; // illustrates if the manager is processing a request
bool isAtEnd; // signifies if the list has shown all the data
bool hasResults; // signifies if the search results has any data
int start; //signifies the start index in the original list of scholarship from data request

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

final int size = 10; //The amount of scholarships added during each request

ScholarshipList({scholarships}){
this.scholarships = scholarships;
start = 0;
isPerformingRequest = false;
isAtEnd = false;
hasResults = true;


//If the original list of scholarships has a length less than size then it will assigned the list as the viewList
//otherwise it will get a list with length of size from the original list and assign it to viewlist
if(scholarships.length <= size){
viewList = scholarships.getRange(start, scholarships.length).toList();
start += (scholarships.length - start);
}else{
viewList = scholarships.getRange(start, start+size).toList();
start += size;
}
current = viewList;
}

//Getter Methods
List<Scholarship> get scholarList => current;
bool get atEnd => isAtEnd;
bool get doesHaveResults => hasResults;
bool get processRequests => isPerformingRequest;
bool get isViewList => current == viewList;
bool get isSearching => current != scholarships;

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

//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")];
hasResults = false;
}else if(query == ""){
current = viewList;
hasResults = true;
}else{
hasResults = true;
}


notifyListeners();

}

void getMoreData() async{

if (!isPerformingRequest) {

isPerformingRequest = true;

notifyListeners();

List<Scholarship> newEntries; //new entries of scholarships for the paginated list

if((scholarships.length - start) == 0){
newEntries = [];
}else if((scholarships.length - start) < size){
newEntries = scholarships.getRange(start, scholarships.length).toList();
start += (scholarships.length - start);
}else {
newEntries = scholarships.getRange(start, start+size).toList();
start += size;
}

if (newEntries.isEmpty){
isAtEnd = true;
}

await Debouncer.wait();

viewList.addAll(newEntries);
isPerformingRequest = false;

notifyListeners();
}
}

//switches the list to the paginated list
void switchList(){
current = viewList;
notifyListeners();
}


}
10 changes: 7 additions & 3 deletions lib/screens/scholarship_screen/local_widget/scholar_card.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
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_details.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

class ScholarCard extends StatelessWidget {
final Scholarship scholarship;
Expand All @@ -14,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 All @@ -27,9 +30,10 @@ class ScholarCard extends StatelessWidget {
);
}

/// Builds the transition for [ScholarshipDetails], Transition: Slide In from the left
PageRouteBuilder _buildTransition(){
return PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => ScholarshipDetails(current: scholarship),
pageBuilder: (context, animation, secondaryAnimation) => ScholarshipDetailsView(current: scholarship,),
transitionDuration: Duration(milliseconds: 500,),
transitionsBuilder: (context, animation, secondaryAnimation, child){
animation = CurvedAnimation(
Expand Down
Loading

0 comments on commit 385952b

Please sign in to comment.