Submit Receipt fixed

'find' works, recurring options work, only thing that needs doing is adding organisation's address to api request
This commit is contained in:
Felix 2019-07-15 14:48:41 +01:00
parent 60873a07ef
commit a3a52ebe4a
3 changed files with 92 additions and 136 deletions

View file

@ -26,12 +26,12 @@ List<Organisation> jsonToOrganisations(String json) {
List<dynamic> validated = decoded['unvalidated']; List<dynamic> validated = decoded['unvalidated'];
// Map organisation = validated[0]; // Map organisation = validated[0];
//
print(""); // print("");
print("Response:"); // print("Response:");
for (var i = 0; i < validated.length; i++) { // for (var i = 0; i < validated.length; i++) {
print(validated[i]); // print(validated[i]);
} // }
List<Map> organisationsMaps = new List<Map>(); List<Map> organisationsMaps = new List<Map>();
@ -61,14 +61,14 @@ List<Organisation> jsonToOrganisations(String json) {
// the reason some organizations do not show up is because they are not all validated // 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 // option to 'show unvalidated' should be added along with maybe a settings section
//
print(""); // print("");
print("Local:"); // print("Local:");
for (var i = 0; i < organisations.length; i++) // for (var i = 0; i < organisations.length; i++)
{ // {
print(organisations[i].name); // print(organisations[i].name);
} // }
print(""); // print("");
return organisations; return organisations;
} }

View file

@ -1,20 +1,22 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'dart:async';
class PopupListView { class PopupListView {
List<String> options = new List<String>(); Future<dynamic> dialog(context, List<String> options, String title) {
var context; return showDialog<dynamic>(
String listTitle; context: context,
List<SimpleDialogOption> simpleDialogOptions = new List<SimpleDialogOption>(); barrierDismissible: false,
String result;
PopupListView(context, List<String> options, String title) { builder: (BuildContext context) {
this.context = context; return SimpleDialog(
this.options = options; title: Text(title),
this.listTitle = title; children: getDialogOptions(context, options),
);
},
);
} }
List<Widget> getDialogOptions(context, List<String> options /*, Function onPressed*/) {
List<SimpleDialogOption> getDialogOptions() {
var dialogOptionsList = new List<SimpleDialogOption>(); var dialogOptionsList = new List<SimpleDialogOption>();
for (var i = 0; i < options.length; i++) { for (var i = 0; i < options.length; i++) {
@ -23,9 +25,7 @@ class PopupListView {
// print each iteration to see if any are null // print each iteration to see if any are null
child: Text(options[i]), child: Text(options[i]),
onPressed: () { onPressed: () {
Navigator.of(this.context).pop(); Navigator.of(context).pop(options[i]);
// print("Chosen organisation is " + options[i]);
optionChosen(options[i]);
}, },
), ),
); );
@ -33,19 +33,4 @@ class PopupListView {
return dialogOptionsList; return dialogOptionsList;
} }
Widget dialog() {
return new SimpleDialog(
title: Text(listTitle),
children : getDialogOptions(),
);
} }
void optionChosen(String option) {
// now pass `option` to
}
}

View file

@ -29,10 +29,9 @@ class ReceiptPageState extends State<ReceiptPage> {
final TextEditingController _timeController = TextEditingController(); final TextEditingController _timeController = TextEditingController();
final TextEditingController _amountController = TextEditingController(); final TextEditingController _amountController = TextEditingController();
final TextEditingController _essentialController = TextEditingController(); final TextEditingController _essentialController = TextEditingController();
final TextEditingController _recurringController = TextEditingController(); final TextEditingController _recurringController = TextEditingController(text: "None");
final TextEditingController _typeController = TextEditingController(); final TextEditingController _typeController = TextEditingController();
final TextEditingController _orgController = 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 FocusNode focusNode; // added so focus can move automatically
@ -70,6 +69,8 @@ class ReceiptPageState extends State<ReceiptPage> {
await preferences.setString('LastPageRoute', lastRoute); await preferences.setString('LastPageRoute', lastRoute);
} }
// this file is getting really messy sorry everyone
void submitReceipt(String amount, String time, String orgName) async { void submitReceipt(String amount, String time, String orgName) async {
SystemChannels.textInput.invokeMethod('TextInput.hide'); SystemChannels.textInput.invokeMethod('TextInput.hide');
@ -125,6 +126,19 @@ class ReceiptPageState extends State<ReceiptPage> {
return "false"; return "false";
} }
List<String> getOptions() {
var options = new List<String>(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) { String formatDate(String date) {
// return ""; // return "";
// should be in format: // should be in format:
@ -158,21 +172,15 @@ class ReceiptPageState extends State<ReceiptPage> {
optionsList.add(organisations[i].name); 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( dialog.then((value) => _orgController.text = value);
context: context, //can't return value as it is <future> and thus would block
builder: (BuildContext context) {
return dialog;
},
);
print(popupListView.result);
return popupListView.result;
} }
@override @override
@ -285,16 +293,31 @@ class ReceiptPageState extends State<ReceiptPage> {
padding: EdgeInsets.fromLTRB(5,0,0,4), // sorry about hardcoded constraints padding: EdgeInsets.fromLTRB(5,0,0,4), // sorry about hardcoded constraints
child: FlatButton( child: FlatButton(
onPressed: () { onPressed: () {
var organisations = findOrganisations(_orgController.text); if (_orgController.text != "") {
// some tasty async stuff here yum yum var organisations = findOrganisations(
// and a pretty little dialog too yay (doesn't work) _orgController.text);
var choice = organisations.then((data) => listOrganisations(data, context));
// choice is a Future<String> 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", child: Text("Find",
style: style: TextStyle(color: Colors.blue, fontSize: 18.0)
TextStyle(color: Colors.blue, fontSize: 18.0)), ),
), ),
), ),
) )
@ -369,10 +392,10 @@ class ReceiptPageState extends State<ReceiptPage> {
), ),
Padding( Padding(
padding: EdgeInsets.fromLTRB(0.0,25,0.0,0.0), padding: EdgeInsets.fromLTRB(0.0,18,0.0,0.0),
child : Container ( child : Container (
height: 27, height: 35,
// width: 400, // width: 400,
child : ListView( child : ListView(
@ -380,6 +403,7 @@ class ReceiptPageState extends State<ReceiptPage> {
children: <Widget>[ children: <Widget>[
Container( Container(
padding: const EdgeInsets.fromLTRB(0, 7, 0, 8),
child: Text( child: Text(
"Recurring", "Recurring",
style: TextStyle( style: TextStyle(
@ -390,81 +414,28 @@ class ReceiptPageState extends State<ReceiptPage> {
), ),
Container( Container(
child : Padding( padding: const EdgeInsets.fromLTRB(29, 0, 0, 0),
padding: EdgeInsets.fromLTRB(15.0, 0.0, 0, 4), child: DropdownButton<String>(
value: _recurringController.text,
child: Checkbox(value: onChanged: (String newValue) {
_essentialController.text.toLowerCase() != "none" ||
_essentialController.text.toLowerCase() != 'false',
onChanged: (bool newValue) {
setState(() { setState(() {
var options = new List<String>(7); _recurringController.text = newValue;
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;
}); });
}), },
), items: getOptions().map<DropdownMenuItem<String>>((String value) {
), return DropdownMenuItem<String>(
value: value,
Container( child: Text(value),
padding: EdgeInsets.fromLTRB(10, 2, 0, 0), );
child: Text( })
convertBoolToString(_essentialController.text.toLowerCase() != "none" || .toList(),
_essentialController.text.toLowerCase() != 'false'), )
style: TextStyle(
fontSize: 16.0,
color: Colors.grey,
),
),
), ),
], ],
), ),
), ),
), ),
// var options = new List<String>(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(
padding: EdgeInsets.fromLTRB(0.0, 40.0, 0.0, 0.0), padding: EdgeInsets.fromLTRB(0.0, 40.0, 0.0, 0.0),
child: Container( child: Container(