Added 'essential purchase' option, its Y position relative to the text still needs sorting out though

This commit is contained in:
Felix 2019-07-05 15:34:39 +01:00
parent f31a2ae44b
commit 1b98ed6ca0
4 changed files with 126 additions and 41 deletions

View file

@ -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\
}

View file

@ -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<LoginModel> 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<String, String> 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'),
};

View file

@ -55,6 +55,12 @@ class LoginPageState extends State<LoginPage> {
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<LoginPage> {
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<LoginPage> {
height: 65.0,
child: RaisedButton(
onPressed: () {
SystemChannels.textInput.invokeMethod('TextInput.hide');
requestLoginAPI(context, _emailController.text,
login( _emailController.text,
_passwordController.text);
// showDialog(
// barrierDismissible: false,

View file

@ -54,6 +54,49 @@ class ReceiptPageState extends State<ReceiptPage> {
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: <Widget>[
// 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<ReceiptPage> {
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: <Widget>[
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: