diff --git a/lib/common/apifunctions/categories.dart b/lib/common/apifunctions/categories.dart index 6cdf153..dc537ab 100644 --- a/lib/common/apifunctions/categories.dart +++ b/lib/common/apifunctions/categories.dart @@ -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>> getCategoriesList() async { + //TODO: Return a list of [String, String] where {1} is categoryName and {2} is categoryValue for request + var categoriesList = List(); + + 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> getCategories() async { // confusing name const url = "https://dev.peartrade.org/api/search/category"; var token; diff --git a/lib/common/apifunctions/find_organisations.dart b/lib/common/apifunctions/find_organisations.dart index 68cc339..8ad1fdf 100644 --- a/lib/common/apifunctions/find_organisations.dart +++ b/lib/common/apifunctions/find_organisations.dart @@ -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 jsonToOrganisations(String json) { Map decoded = jsonDecode(json); -// print(decoded); - List validated = decoded['validated']; -// Map organisation = validated[0]; -// -// print(""); -// print("Response:"); -// for (var i = 0; i < validated.length; i++) { -// print(validated[i]); -// } - List organisationsMaps = new List(); - validated.forEach((element) => organisationsMaps.add(element)); - -// print(""); -// print("organisationsMaps:"); -// print(organisationsMaps); - List organisations = new List(); - -// 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 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> findOrganisations(String search) async { body: json.encode(body), ); -// print(response.body); - if (response.statusCode == 200) { //request successful return jsonToOrganisations(response.body); diff --git a/lib/common/widgets/organisations_dialog.dart b/lib/common/widgets/organisations_dialog.dart new file mode 100644 index 0000000..ab000ac --- /dev/null +++ b/lib/common/widgets/organisations_dialog.dart @@ -0,0 +1,79 @@ +import 'package:flutter/material.dart'; +import 'dart:async'; + +import 'package:local_spend/common/apifunctions/find_organisations.dart'; + +class FindOrganisations { + + TextField getSearchBar(TextEditingController controller, String hintText) { + return TextField( + controller: controller, + decoration: InputDecoration( + hintText: hintText, + icon: Icon(Icons.search), + ), + ); + } + + List getStuff() { + var numItems = 200; + var itemsList = new List(); + + for (int i = 0; i < numItems; i++) { + itemsList.add(Text( + "Payee " + (i + 1).toString(), + style: new TextStyle(fontSize: 18), + )); + } + + return itemsList; + } + + Future dialog(context) { + var searchBar = getSearchBar(null, "Payee Name"); + var stuff = getStuff(); + return showDialog( + context: context, + barrierDismissible: true, + + builder: (BuildContext context) { + return SimpleDialog( + children: [ + Padding( + padding: EdgeInsets.symmetric(horizontal: 10), + child: searchBar, + ), + + Container( + padding: EdgeInsets.all(10), + width: MediaQuery.of(context).size.width * 0.7, + height: MediaQuery.of(context).size.height * 0.7, + + child: Material( + shadowColor: Colors.transparent, + color: Colors.transparent, + child: ListView.builder( + itemCount: stuff.length, + itemBuilder: (context, index) { + return Card( + child: ListTile( + leading: Icon(Icons.person), + title: stuff[index], + trailing: Icon(Icons.arrow_forward_ios), + ) + ); + }, + ), + ), + ), + + + // help button for if org not listed + // cancel and ok buttons + + ], + ); + }, + ); + } +} \ No newline at end of file diff --git a/lib/pages/receipt_page_2.dart b/lib/pages/receipt_page_2.dart index 208c5fa..f58c4db 100644 --- a/lib/pages/receipt_page_2.dart +++ b/lib/pages/receipt_page_2.dart @@ -2,17 +2,27 @@ import 'package:flutter/material.dart'; import 'package:local_spend/common/platform/platform_scaffold.dart'; import 'package:intl/intl.dart'; import 'package:flutter/cupertino.dart'; +import 'package:local_spend/common/apifunctions/find_organisations.dart'; +import 'package:local_spend/common/widgets/organisations_dialog.dart'; class Transaction { DateTime date; - double amount; - + TextEditingController amount; + Organisation organisation; + Transaction( this.date, this.amount, + this.organisation, ); } +// Find Organisations + + + +// end Find Organisations + class ReceiptPage2 extends StatefulWidget { @override State createState() { @@ -21,7 +31,11 @@ class ReceiptPage2 extends StatefulWidget { } class ReceiptPage2State extends State { - Transaction transaction = new Transaction(DateTime.now(), 0); + Transaction transaction = new Transaction( + DateTime.now(), + new TextEditingController(), + new Organisation(null, null, null, null, null), + ); @override Widget build(BuildContext context) { @@ -116,6 +130,50 @@ class ReceiptPage2State extends State { ), ), // Date/Time picker + Container( + padding: EdgeInsets.fromLTRB(25,15,15.0,0.0), + child: Row( + children: [ + Container( + child : Text( + "Payee", + style: TextStyle( + fontSize: 18, + color: Colors.black, + fontWeight: FontWeight.bold, + ), + ), + width: 110, + ), + + Container( + padding: const EdgeInsets.fromLTRB(0, 0, 0, 0), + height: 32.0, + child: RaisedButton( + onPressed: () { +// var popupListView = new PopupListView(); +// var dialog = popupListView.dialog(context, optionsList, "Choose Organization"); + var organisations = new FindOrganisations(); + var orgDialog = organisations.dialog(context); + + orgDialog.then((organisation) { + debugPrint(organisation.name); + }); + }, + child: Text( + transaction.organisation.name == null + ? 'Find' + : transaction.organisation.name, + style: + TextStyle(color: Colors.white, fontSize: 18.0), + ), + color: Colors.blue, + ), + ), + ], + ), + ), // Organisation picker + Container( padding: EdgeInsets.fromLTRB(25,15,15.0,0.0), child: Row( @@ -136,23 +194,13 @@ class ReceiptPage2State extends State { Container( padding: const EdgeInsets.fromLTRB(0, 0, 0, 0), height: 32.0, - child: RaisedButton( - onPressed: () { - showModalBottomSheet( - context: context, - builder: (BuildContext builder) { - return Container( - height: MediaQuery.of(context).copyWith().size.height / 3, - ); - }); - },// onPressed: () => showDatePicker(context: context, initialDate: _transactionDate, firstDate: null, lastDate: _transactionDate), - child: Text( - transaction.amount == null - ? 'None set.' - : "£" + transaction.amount.toString() + "0", - style : TextStyle(color: Colors.white, fontSize: 18.0), + width: 100, + child: TextField( + controller: transaction.amount, + decoration: InputDecoration( + hintText: "£0.00" ), - color: Colors.blue, + keyboardType: TextInputType.number, ), ), ],