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:
parent
60873a07ef
commit
a3a52ebe4a
3 changed files with 92 additions and 136 deletions
|
@ -26,12 +26,12 @@ List<Organisation> jsonToOrganisations(String json) {
|
|||
|
||||
List<dynamic> 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<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
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'dart:async';
|
||||
|
||||
class PopupListView {
|
||||
List<String> options = new List<String>();
|
||||
var context;
|
||||
String listTitle;
|
||||
List<SimpleDialogOption> simpleDialogOptions = new List<SimpleDialogOption>();
|
||||
String result;
|
||||
Future<dynamic> dialog(context, List<String> options, String title) {
|
||||
return showDialog<dynamic>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
|
||||
PopupListView(context, List<String> 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<SimpleDialogOption> getDialogOptions() {
|
||||
List<Widget> getDialogOptions(context, List<String> options /*, Function onPressed*/) {
|
||||
var dialogOptionsList = new List<SimpleDialogOption>();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -29,10 +29,9 @@ class ReceiptPageState extends State<ReceiptPage> {
|
|||
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<ReceiptPage> {
|
|||
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<ReceiptPage> {
|
|||
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) {
|
||||
// return "";
|
||||
// should be in format:
|
||||
|
@ -158,21 +172,15 @@ class ReceiptPageState extends State<ReceiptPage> {
|
|||
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 <future> and thus would block
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -285,16 +293,31 @@ class ReceiptPageState extends State<ReceiptPage> {
|
|||
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<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",
|
||||
style:
|
||||
TextStyle(color: Colors.blue, fontSize: 18.0)),
|
||||
style: TextStyle(color: Colors.blue, fontSize: 18.0)
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
@ -369,10 +392,10 @@ class ReceiptPageState extends State<ReceiptPage> {
|
|||
),
|
||||
|
||||
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<ReceiptPage> {
|
|||
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(0, 7, 0, 8),
|
||||
child: Text(
|
||||
"Recurring",
|
||||
style: TextStyle(
|
||||
|
@ -390,81 +414,28 @@ class ReceiptPageState extends State<ReceiptPage> {
|
|||
),
|
||||
|
||||
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<String>(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<String>(
|
||||
value: _recurringController.text,
|
||||
onChanged: (String newValue) {
|
||||
setState(() {
|
||||
_recurringController.text = newValue;
|
||||
});
|
||||
},
|
||||
items: getOptions().map<DropdownMenuItem<String>>((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
// 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: EdgeInsets.fromLTRB(0.0, 40.0, 0.0, 0.0),
|
||||
child: Container(
|
||||
|
|
Reference in a new issue