From 1b98ed6ca0acf6c4b85b902c2a293beb4a733d26 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 5 Jul 2019 15:34:39 +0100 Subject: [PATCH] Added 'essential purchase' option, its Y position relative to the text still needs sorting out though --- To Do List.rtf | 8 +- .../apifunctions/submit_receipt_api.dart | 27 +++- lib/pages/login_page.dart | 12 +- lib/pages/receipt_page.dart | 120 ++++++++++++++---- 4 files changed, 126 insertions(+), 41 deletions(-) diff --git a/To Do List.rtf b/To Do List.rtf index a8c4945..5e0608e 100644 --- a/To Do List.rtf +++ b/To Do List.rtf @@ -45,10 +45,6 @@ \pard\tx940\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li1440\fi-1440\pardirnatural\partightenfactor0 \ls5\ilvl1\cf0 \ulnone {\listtext \uc0\u8259 } \f1\b0 Categories\ -{\listtext -\f0\b \uc0\u8259 -\f1\b0 }Recurring\ -{\listtext -\f0\b \uc0\u8259 -\f1\b0 }Essential/non-essential\ +{\listtext \uc0\u8259 }Recurring\ +{\listtext \uc0\u8259 }Sort out \'91essential purchase\'92 checkbox\'92s Y position\ } \ No newline at end of file diff --git a/lib/common/apifunctions/submit_receipt_api.dart b/lib/common/apifunctions/submit_receipt_api.dart index 70c56f1..c25c5a6 100644 --- a/lib/common/apifunctions/submit_receipt_api.dart +++ b/lib/common/apifunctions/submit_receipt_api.dart @@ -10,16 +10,37 @@ import 'package:local_spend/config.dart'; // debug import 'package:flutter/foundation.dart'; +class Receipt { + var amount = ""; + var time = ""; + var street = ""; + var category = ""; + var organisationName = ""; + var postcode = ""; + var recurring = ""; + var town = ""; + + var essential = "false"; +} + Future submitReceiptAPI( - BuildContext context, String amount, String time) async { + BuildContext context, Receipt receipt) async { //var apiUrl = ConfigWrapper.of(context).apiKey; final url = "https://dev.peartrade.org/api/upload"; SharedPreferences preferences = await SharedPreferences.getInstance(); Map body = { - 'transaction_value': amount, - 'purchase_time': time, + 'transaction_value': receipt.amount, + 'purchase_time': receipt.time, + 'category': receipt.category, + 'essential': receipt.essential, + 'organisation_name': receipt.organisationName, + 'recurring': receipt.recurring, + 'street_name': receipt.street, + 'town': receipt.town, + 'postcode': receipt.postcode, + 'session_key': preferences.get('LastToken'), }; diff --git a/lib/pages/login_page.dart b/lib/pages/login_page.dart index 8ebb064..07d925a 100644 --- a/lib/pages/login_page.dart +++ b/lib/pages/login_page.dart @@ -55,6 +55,12 @@ class LoginPageState extends State { await preferences.setString('LastPageRoute', lastRoute); } + void login(String username, String password) { + SystemChannels.textInput.invokeMethod('TextInput.hide'); + requestLoginAPI(context, username, + password); + } + @override Widget build(BuildContext context) { return WillPopScope( @@ -169,8 +175,7 @@ class LoginPageState extends State { fontWeight: FontWeight.bold, ), onSubmitted: (_) { - SystemChannels.textInput.invokeMethod('TextInput.hide'); - requestLoginAPI(context, _emailController.text, + login( _emailController.text, _passwordController.text); }, ), @@ -181,8 +186,7 @@ class LoginPageState extends State { height: 65.0, child: RaisedButton( onPressed: () { - SystemChannels.textInput.invokeMethod('TextInput.hide'); - requestLoginAPI(context, _emailController.text, + login( _emailController.text, _passwordController.text); // showDialog( // barrierDismissible: false, diff --git a/lib/pages/receipt_page.dart b/lib/pages/receipt_page.dart index 5141df1..c24f47d 100644 --- a/lib/pages/receipt_page.dart +++ b/lib/pages/receipt_page.dart @@ -54,6 +54,49 @@ class ReceiptPageState extends State { await preferences.setString('LastPageRoute', lastRoute); } + void submitReceipt(String amount, String time) async { + SystemChannels.textInput.invokeMethod('TextInput.hide'); + + if (demonstration) + { + await showDialog( + context: context, + builder: (BuildContext context) { + // return object of type Dialog + return AlertDialog( + title: new Text("Success"), + content: new Text("Recepit successfully submitted."), + actions: [ + // usually buttons at the bottom of the dialog + new FlatButton( + child: new Text("OK"), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ).then((_) { + Navigator.of(context).pushNamed('/HomePage'); + }); + } + else { + Receipt receipt = new Receipt(); + + // setting up 'receipt' + receipt.amount = amount; + receipt.time = time; + + //TODO: initialise receipt with correct values from form + +// receipt.category = category; +// receipt.etc = etc; + + submitReceiptAPI(context, receipt); + } + } + @override Widget build(BuildContext context) { var drawer = Drawer(); @@ -137,43 +180,64 @@ class ReceiptPageState extends State { fontWeight: FontWeight.bold, ), onSubmitted: (_) { - SystemChannels.textInput.invokeMethod('TextInput.hide'); - - if (demonstration) - { - showDialogSingleButton( - context, - "Success", - "Recepit successfully submitted.", - "OK"); - } - else { - submitReceiptAPI(context, _amountController.text, - _timeController.text); - } + submitReceipt(_amountController.text, _timeController.text); }, ), ), + + Padding( + padding: EdgeInsets.fromLTRB(0.0, 35.0, 0.0, 0.0), + + child : Container ( + height: 18, + + child : ListView( + scrollDirection: Axis.horizontal, + + children: [ + Container( + child: Text( + "Essential Purchase", + style: TextStyle( + fontSize: 18.0, + color: Colors.black, + fontWeight: FontWeight.bold, + ), + ), + ), + + Container( + child : Padding( + padding: EdgeInsets.fromLTRB(20.0, 0.0, 0, 0), + + child: Checkbox(value: _essentialController.text.toLowerCase() == 'true', onChanged: (bool newValue) { + setState(() { + var newValueString = "false"; + + if (newValue) + { + newValueString = "true"; + } + + _essentialController.text = newValueString; + }); + }), + ), + ), + + ], + ), + ), + ), + + Padding( padding: EdgeInsets.fromLTRB(0.0, 70.0, 0.0, 0.0), child: Container( height: 65.0, child: RaisedButton( onPressed: () { - SystemChannels.textInput.invokeMethod('TextInput.hide'); - - if (demonstration) - { - showDialogSingleButton( - context, - "Success", - "Recepit successfully submitted.", - "OK"); - } - else { - submitReceiptAPI(context, _amountController.text, - _timeController.text); - } + submitReceipt(_amountController.text, _timeController.text); }, child: Text("SUBMIT", style: