organisations working sorta

This commit is contained in:
Felix 2019-08-07 15:32:52 +01:00
parent aa6de5559a
commit 1e40d78dcd
3 changed files with 168 additions and 117 deletions

View file

@ -4,7 +4,6 @@ import 'package:http/http.dart' as http;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:local_spend/common/functions/get_token.dart'; import 'package:local_spend/common/functions/get_token.dart';
class Organisation { class Organisation {
var id = 0; var id = 0;
var name = ""; var name = "";
@ -22,7 +21,26 @@ class Organisation {
} }
List<Organisation> jsonToOrganisations(String json) { class Organisations {
List<Organisation> getTestData() {
var numItems = 200;
var itemsList = new List<Organisation>();
for (int i = 0; i < numItems; i++) {
itemsList.add(new Organisation(
i,
"Payee " + (i + 1).toString(),
"eee eee",
"yeet street",
"Robloxia"
));
}
return itemsList;
}
List<Organisation> _jsonToOrganisations(String json) {
Map decoded = jsonDecode(json); Map decoded = jsonDecode(json);
List<dynamic> validated = decoded['validated']; List<dynamic> validated = decoded['validated'];
List<Map> organisationsMaps = new List<Map>(); List<Map> organisationsMaps = new List<Map>();
@ -44,9 +62,9 @@ List<Organisation> jsonToOrganisations(String json) {
} }
return organisations; return organisations;
} }
Future<List<Organisation>> findOrganisations(String search) async { Future<List<Organisation>> findOrganisations(String search) async {
final url = "https://dev.peartrade.org/api/search"; final url = "https://dev.peartrade.org/api/search";
var token; var token;
@ -66,14 +84,11 @@ Future<List<Organisation>> findOrganisations(String search) async {
if (response.statusCode == 200) { if (response.statusCode == 200) {
//request successful //request successful
return jsonToOrganisations(response.body); return _jsonToOrganisations(response.body);
} else { } else {
// not successful // not successful
return null; return null;
} }
} }
class OrganizationController extends TextEditingController {
Organisation organisation;
} }

View file

@ -15,61 +15,101 @@ class FindOrganisations {
); );
} }
List<Text> getFavourites() {
var numItems = 200;
var itemsList = new List<Text>();
for (int i = 0; i < numItems; i++) {
itemsList.add(Text(
"Payee " + (i + 1).toString(),
style: new TextStyle(fontSize: 18),
));
}
return itemsList;
}
// todo: get all organisations, favourites and all data from one 'organisations' class or similar // todo: get all organisations, favourites and all data from one 'organisations' class or similar
// eg items: organisations.getFavourites().orderBy(name), // eg items: organisations.getFavourites().orderBy(name),
Future<Organisation> dialog(context) { Future<Organisation> dialog(context) {
var searchBar = getSearchBar(null, "Payee Name"); TextEditingController searchBarText = new TextEditingController();
var favourites = getFavourites(); var organisations = new Organisations();
var listTitle = "All Organisations";
var organisationsList = organisations.getTestData();
void _submitSearch(String search) {
listTitle = "Results for \'" + search + "\'";
var futureOrgs = organisations.findOrganisations(search);
futureOrgs.then((val) {
debugPrint("There are " + val.length.toString() +
" payees matching the query \'" + search + "\'.");
organisationsList = val;
});
}
return showDialog<Organisation>( return showDialog<Organisation>(
context: context, context: context,
barrierDismissible: true, barrierDismissible: true,
builder: (BuildContext context) { builder: (BuildContext context) {
return StatefulBuilder(
builder: (context, setState) {
return SimpleDialog( return SimpleDialog(
children: <Widget>[ children: <Widget>[
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: 10), padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
child: searchBar, child: Row(
children: [
Container(
width: 200,
height: 50,
child: TextField(
controller: searchBarText,
decoration: InputDecoration(
hintText: "Payee Name",
),
onSubmitted: (_) {
_submitSearch(searchBarText.text);
setState(() => {});
},
),
), ),
Container( Container(
padding: EdgeInsets.fromLTRB(20, 20, 0, 0), width: 80,
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
child: RaisedButton(
onPressed: () {
_submitSearch(searchBarText.text);
setState(() => {});
},
child: Icon(Icons.search, color: Colors.white),
color: Colors.blue,
// make inactive when search in progress as activity indicator
),
),
],
),
),
Container(
padding: EdgeInsets.fromLTRB(20, 20, 20, 0),
child: Text( child: Text(
"Favourites", listTitle,
style: new TextStyle(fontSize: 23, fontWeight: FontWeight.bold), style: new TextStyle(
fontSize: 23, fontWeight: FontWeight.bold),
), ),
), ),
Container( Container(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0), padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
width: MediaQuery.of(context).size.width * 0.7, width: MediaQuery
height: MediaQuery.of(context).size.height * 0.67, .of(context)
.size
.width * 0.7,
height: MediaQuery
.of(context)
.size
.height * 0.67,
child: Material( child: Material(
shadowColor: Colors.transparent, shadowColor: Colors.transparent,
color: Colors.transparent, color: Colors.transparent,
child: ListView.builder( child: ListView.builder(
itemCount: favourites.length, itemCount: organisationsList.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return Card( return Card(
child: ListTile( child: ListTile(
leading: Icon(Icons.person), leading: Icon(Icons.person),
title: favourites[index], title: Text(organisationsList[index].name, style: new TextStyle(fontSize: 18)),
trailing: Icon(Icons.arrow_forward_ios), trailing: Icon(Icons.arrow_forward_ios),
onTap: () {}, onTap: () {},
) )
@ -87,5 +127,7 @@ class FindOrganisations {
); );
}, },
); );
},
);
} }
} }

View file

@ -17,12 +17,6 @@ class Transaction {
); );
} }
// Find Organisations
// end Find Organisations
class ReceiptPage2 extends StatefulWidget { class ReceiptPage2 extends StatefulWidget {
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {