diff --git a/lib/common/apifunctions/find_organisations.dart b/lib/common/apifunctions/find_organisations.dart index 4c6346a..69187e8 100644 --- a/lib/common/apifunctions/find_organisations.dart +++ b/lib/common/apifunctions/find_organisations.dart @@ -26,12 +26,12 @@ List jsonToOrganisations(String json) { List validated = decoded['unvalidated']; // Map organisation = validated[0]; - - print(""); - print("Response:"); - for (var i = 0; i < validated.length; i++) { - print(validated[i]); - } +// +// print(""); +// print("Response:"); +// for (var i = 0; i < validated.length; i++) { +// print(validated[i]); +// } List organisationsMaps = new List(); @@ -61,14 +61,14 @@ List jsonToOrganisations(String json) { // 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(""); +// +// print(""); +// print("Local:"); +// for (var i = 0; i < organisations.length; i++) +// { +// print(organisations[i].name); +// } +// print(""); return organisations; } diff --git a/lib/common/widgets/popupListView.dart b/lib/common/widgets/popupListView.dart index c0784c0..ceea50a 100644 --- a/lib/common/widgets/popupListView.dart +++ b/lib/common/widgets/popupListView.dart @@ -1,20 +1,22 @@ import 'package:flutter/material.dart'; +import 'dart:async'; class PopupListView { - List options = new List(); - var context; - String listTitle; - List simpleDialogOptions = new List(); - String result; + Future dialog(context, List options, String title) { + return showDialog( + context: context, + barrierDismissible: false, - PopupListView(context, List options, String title) { - this.context = context; - this.options = options; - this.listTitle = title; + builder: (BuildContext context) { + return SimpleDialog( + title: Text(title), + children: getDialogOptions(context, options), + ); + }, + ); } - - List getDialogOptions() { + List getDialogOptions(context, List options /*, Function onPressed*/) { var dialogOptionsList = new List(); for (var i = 0; i < options.length; i++) { @@ -23,9 +25,7 @@ class PopupListView { // print each iteration to see if any are null child: Text(options[i]), onPressed: () { - Navigator.of(this.context).pop(); -// print("Chosen organisation is " + options[i]); - optionChosen(options[i]); + Navigator.of(context).pop(options[i]); }, ), ); @@ -33,19 +33,4 @@ class PopupListView { return dialogOptionsList; } - - Widget dialog() { - return new SimpleDialog( - title: Text(listTitle), - children : getDialogOptions(), - ); - } - - void optionChosen(String option) { - // now pass `option` to - } -} - - - - +} \ No newline at end of file diff --git a/lib/pages/receipt_page.dart b/lib/pages/receipt_page.dart index 3715904..1c24bf3 100644 --- a/lib/pages/receipt_page.dart +++ b/lib/pages/receipt_page.dart @@ -29,10 +29,9 @@ class ReceiptPageState extends State { final TextEditingController _timeController = TextEditingController(); final TextEditingController _amountController = TextEditingController(); final TextEditingController _essentialController = TextEditingController(); - final TextEditingController _recurringController = TextEditingController(); + final TextEditingController _recurringController = TextEditingController(text: "None"); final TextEditingController _typeController = TextEditingController(); final TextEditingController _orgController = TextEditingController(); - bool _recurringCheckbox = false; // have mercy, this will be removed. sorry for this variable's placement... FocusNode focusNode; // added so focus can move automatically @@ -70,6 +69,8 @@ class ReceiptPageState extends State { await preferences.setString('LastPageRoute', lastRoute); } + // this file is getting really messy sorry everyone + void submitReceipt(String amount, String time, String orgName) async { SystemChannels.textInput.invokeMethod('TextInput.hide'); @@ -125,6 +126,19 @@ class ReceiptPageState extends State { return "false"; } + List getOptions() { + var options = new List(7); + options[0] = "None"; + options[1] = "Daily"; + options[2] = "Weekly"; + options[3] = "Fortnightly"; + options[4] = "Monthly"; + options[5] = "Quarterly"; + options[6] = "Yearly"; + + return options; + } + String formatDate(String date) { // return ""; // should be in format: @@ -158,21 +172,15 @@ class ReceiptPageState extends State { optionsList.add(organisations[i].name); } - var popupListView = new PopupListView(context, optionsList, "Choose Organization"); +// var popupListView = new PopupListView(context, optionsList, "Choose Organization"); - var dialog = popupListView.dialog(); + var popupListView = new PopupListView(); + var dialog = popupListView.dialog(context, optionsList, "Choose Organization"); -// print(dialog); +// dialog.then((value) => debugPrint(value)); - showDialog( - context: context, - builder: (BuildContext context) { - return dialog; - }, - ); - - print(popupListView.result); - return popupListView.result; + dialog.then((value) => _orgController.text = value); + //can't return value as it is and thus would block } @override @@ -285,16 +293,31 @@ class ReceiptPageState extends State { padding: EdgeInsets.fromLTRB(5,0,0,4), // sorry about hardcoded constraints child: FlatButton( onPressed: () { - var organisations = findOrganisations(_orgController.text); - // some tasty async stuff here yum yum - // and a pretty little dialog too yay (doesn't work) - var choice = organisations.then((data) => listOrganisations(data, context)); + if (_orgController.text != "") { + var organisations = findOrganisations( + _orgController.text); - // choice is a Future + var choice = organisations.then((data) => + listOrganisations(data, context)); + + choice.then((value) => _orgController.text = value); + setState(() { + + }); + } else { + // no data entered + + showDialogSingleButton( + context, + "No data", + "We were unable to service your request because no data was entered.", + "OK" + ); + } }, child: Text("Find", - style: - TextStyle(color: Colors.blue, fontSize: 18.0)), + style: TextStyle(color: Colors.blue, fontSize: 18.0) + ), ), ), ) @@ -369,10 +392,10 @@ class ReceiptPageState extends State { ), Padding( - padding: EdgeInsets.fromLTRB(0.0,25,0.0,0.0), + padding: EdgeInsets.fromLTRB(0.0,18,0.0,0.0), child : Container ( - height: 27, + height: 35, // width: 400, child : ListView( @@ -380,6 +403,7 @@ class ReceiptPageState extends State { children: [ Container( + padding: const EdgeInsets.fromLTRB(0, 7, 0, 8), child: Text( "Recurring", style: TextStyle( @@ -390,81 +414,28 @@ class ReceiptPageState extends State { ), Container( - child : Padding( - padding: EdgeInsets.fromLTRB(15.0, 0.0, 0, 4), - - child: Checkbox(value: - _essentialController.text.toLowerCase() != "none" || - _essentialController.text.toLowerCase() != 'false', - onChanged: (bool newValue) { - setState(() { - var options = new List(7); - options[0] = "Daily"; - options[1] = "Weekly"; - options[2] = "Fortnightly"; - options[3] = "Monthly"; - options[5] = "Quarterly"; - options[6] = "Yearly"; - - var popupListView = new PopupListView( - context, options, "Recurring..."); - - var dialog = popupListView.dialog(); - - showDialog( - context: context, - builder: (BuildContext context) { - return dialog; - }, - ); - - print(popupListView.result); -// _recurringController.text = -// popupListView.result; - }); - }), - ), - ), - - Container( - padding: EdgeInsets.fromLTRB(10, 2, 0, 0), - child: Text( - convertBoolToString(_essentialController.text.toLowerCase() != "none" || - _essentialController.text.toLowerCase() != 'false'), - style: TextStyle( - fontSize: 16.0, - color: Colors.grey, - ), - ), + padding: const EdgeInsets.fromLTRB(29, 0, 0, 0), + child: DropdownButton( + value: _recurringController.text, + onChanged: (String newValue) { + setState(() { + _recurringController.text = newValue; + }); + }, + items: getOptions().map>((String value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }) + .toList(), + ) ), ], ), ), ), - -// var options = new List(1); -// options[0] = "Weekly"; -// -// var popupListView = new PopupListView(context, options, "Recurring..."); -// -// var dialog = popupListView.dialog(); -// -// showDialog( -// context: context, -// builder: (BuildContext context) { -// return dialog; -// }, -// ); -// -// print(popupListView.result); -// _recurringController.text = popupListView.result; -// -// setState(() { -// _recurringController.text = -// convertBoolToString(newValue); - - Padding( padding: EdgeInsets.fromLTRB(0.0, 40.0, 0.0, 0.0), child: Container(