UI looking FANTASTIC

new organisations dialog added with very sexy listView
This commit is contained in:
Felix 2019-08-07 13:15:15 +01:00
parent 59f69b102f
commit eaf7a06f52
4 changed files with 173 additions and 57 deletions

View file

@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'package:local_spend/common/functions/get_token.dart';
import 'package:flutter/material.dart';
class Category {
String name;
@ -13,6 +14,24 @@ class Category {
});
}
Future<List<DropdownMenuItem<String>>> getCategoriesList() async {
//TODO: Return a list of [String, String] where {1} is categoryName and {2} is categoryValue for request
var categoriesList = List<DropdownMenuItem>();
var categories = await getCategories();
categories.forEach((thisCategory) {
var thisMap = new DropdownMenuItem(
child: new Text(thisCategory.name),
value: thisCategory.index,
);
categoriesList.add(thisMap);
});
return categoriesList;
}
Future<List<Category>> getCategories() async { // confusing name
const url = "https://dev.peartrade.org/api/search/category";
var token;

View file

@ -4,6 +4,7 @@ import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:local_spend/common/functions/get_token.dart';
class Organisation {
var id = 0;
var name = "";
@ -11,40 +12,22 @@ class Organisation {
var streetName = ""; //street_name
var town = "";
Organisation(int id, String name, String postcode, String streetName, String town) {
this.id = id;
this.name = name;
this.postcode = postcode;
this.streetName = streetName; //street_name
this.town = town;
}
Organisation(
this.id,
this.name,
this.postcode,
this.streetName,
this.town,
);
}
List<Organisation> jsonToOrganisations(String json) {
Map decoded = jsonDecode(json);
// print(decoded);
List<dynamic> validated = decoded['validated'];
// Map organisation = validated[0];
//
// print("");
// print("Response:");
// for (var i = 0; i < validated.length; i++) {
// print(validated[i]);
// }
List<Map> organisationsMaps = new List<Map>();
validated.forEach((element) => organisationsMaps.add(element));
// print("");
// print("organisationsMaps:");
// print(organisationsMaps);
List<Organisation> organisations = new List<Organisation>();
// organisationsMaps[0].forEach((k,v) => print('${k}: ${v}'));
for (var i = 0; i < organisationsMaps.length; i++) {
final params = organisationsMaps[i].values.toList();
@ -60,17 +43,6 @@ List<Organisation> jsonToOrganisations(String json) {
organisations.add(newOrganisation);
}
// the reason some organizations do not show up is because they are not all validated
// option to 'show unvalidated' should be added along with maybe a settings section
//
// print("");
// print("Local:");
// for (var i = 0; i < organisations.length; i++)
// {
// print(organisations[i].name);
// }
// print("");
return organisations;
}
@ -92,8 +64,6 @@ Future<List<Organisation>> findOrganisations(String search) async {
body: json.encode(body),
);
// print(response.body);
if (response.statusCode == 200) {
//request successful
return jsonToOrganisations(response.body);