2019-05-08 18:54:14 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2019-05-10 11:43:45 +00:00
|
|
|
import 'package:local_spend/common/apifunctions/submit_receipt_api.dart';
|
2019-05-08 18:54:14 +00:00
|
|
|
import 'package:local_spend/common/functions/show_dialog_single_button.dart';
|
|
|
|
import 'package:local_spend/common/platform/platform_scaffold.dart';
|
|
|
|
import 'package:local_spend/common/widgets/basic_drawer.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2019-05-16 16:04:08 +00:00
|
|
|
import 'package:intl/intl.dart';
|
2019-05-10 11:43:45 +00:00
|
|
|
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
|
2019-05-08 18:54:14 +00:00
|
|
|
|
|
|
|
const URL = "https://flutter.io/";
|
|
|
|
|
|
|
|
class ReceiptPage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return new ReceiptPageState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ReceiptPageState extends State<ReceiptPage> {
|
2019-05-10 11:43:45 +00:00
|
|
|
final TextEditingController _timeController = TextEditingController();
|
|
|
|
final TextEditingController _amountController = TextEditingController();
|
|
|
|
final TextEditingController _essentialController = TextEditingController();
|
|
|
|
final TextEditingController _recurringController = TextEditingController();
|
|
|
|
final TextEditingController _typeController = TextEditingController();
|
|
|
|
final TextEditingController _orgController = TextEditingController();
|
2019-05-08 18:54:14 +00:00
|
|
|
|
2019-05-16 16:04:08 +00:00
|
|
|
DateTime date;
|
|
|
|
|
2019-05-08 18:54:14 +00:00
|
|
|
Future launchURL(String url) async {
|
|
|
|
if (await canLaunch(url)) {
|
|
|
|
await launch(url, forceSafariVC: true, forceWebView: true);
|
|
|
|
} else {
|
|
|
|
showDialogSingleButton(
|
|
|
|
context,
|
|
|
|
"Unable to reach your website.",
|
|
|
|
"Currently unable to reach the website $URL. Please try again at a later time.",
|
|
|
|
"OK");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2019-05-10 11:43:45 +00:00
|
|
|
_saveCurrentRoute("/ReceiptPageState");
|
2019-05-08 18:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_saveCurrentRoute(String lastRoute) async {
|
|
|
|
SharedPreferences preferences = await SharedPreferences.getInstance();
|
|
|
|
await preferences.setString('LastPageRoute', lastRoute);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var drawer = Drawer();
|
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: () {
|
|
|
|
if (Navigator.canPop(context)) {
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
|
|
'/HomePage', (Route<dynamic> route) => false);
|
|
|
|
} else {
|
|
|
|
Navigator.of(context).pushReplacementNamed('/HomePage');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: PlatformScaffold(
|
|
|
|
drawer: BasicDrawer(),
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(
|
2019-05-10 11:43:45 +00:00
|
|
|
"Submit Receipt",
|
2019-05-08 18:54:14 +00:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 30.0,
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
centerTitle: true,
|
|
|
|
iconTheme: IconThemeData(color: Colors.black),
|
|
|
|
),
|
|
|
|
body: Container(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(30.0, 0.0, 30.0, 0.0),
|
|
|
|
child: ListView(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 40.0, 0.0, 15.0),
|
|
|
|
child: Text(
|
2019-05-10 11:43:45 +00:00
|
|
|
"Required Fields in bold",
|
|
|
|
style: TextStyle(fontSize: 20.0, color: Colors.black),
|
2019-05-08 18:54:14 +00:00
|
|
|
),
|
|
|
|
)),
|
|
|
|
Text(
|
2019-05-10 11:43:45 +00:00
|
|
|
"Time of Transaction",
|
2019-05-08 18:54:14 +00:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18.0,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
2019-05-16 16:04:08 +00:00
|
|
|
DateTimePickerFormField(
|
|
|
|
inputType: InputType.both,
|
|
|
|
format: DateFormat("EEEE, MMMM d, yyyy 'at' h:mma"),
|
|
|
|
editable: true,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'Date/Time of Transaction', hasFloatingPlaceholder: false),
|
|
|
|
onChanged: (dt) => setState(() => date = dt),
|
2019-05-08 18:54:14 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 35.0, 0.0, 0.0),
|
|
|
|
child: Text(
|
2019-05-10 11:43:45 +00:00
|
|
|
"Amount",
|
2019-05-08 18:54:14 +00:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18.0,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
|
|
|
|
child: TextField(
|
2019-05-10 11:43:45 +00:00
|
|
|
controller: _amountController,
|
2019-05-08 18:54:14 +00:00
|
|
|
decoration: InputDecoration(
|
2019-05-16 16:04:08 +00:00
|
|
|
hintText: 'Value in £',
|
2019-05-08 18:54:14 +00:00
|
|
|
),
|
|
|
|
obscureText: true,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18.0,
|
2019-05-16 16:04:08 +00:00
|
|
|
color: Colors.grey[800],
|
2019-05-08 18:54:14 +00:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
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');
|
2019-05-10 11:43:45 +00:00
|
|
|
submitReceiptAPI(context, _amountController.text,
|
|
|
|
_timeController.text);
|
2019-05-08 18:54:14 +00:00
|
|
|
},
|
|
|
|
child: Text("LOGIN",
|
|
|
|
style:
|
|
|
|
TextStyle(color: Colors.white, fontSize: 22.0)),
|
|
|
|
color: Colors.blue,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|