New navigation system, new 'about/settings/logout' page, some more types of dialog boxes added, some more minor things
This commit is contained in:
Felix 2019-07-15 12:09:10 +01:00
parent 2d0b6230ae
commit 60873a07ef
13 changed files with 1142 additions and 279 deletions

View file

@ -7,7 +7,10 @@ import 'package:flutter_linkify/flutter_linkify.dart';
class AboutPage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
// _HomePageState createState() => _HomePageState();
State<StatefulWidget> createState() {
return new _HomePageState();
}
}
class _HomePageState extends State<AboutPage> {
@ -17,6 +20,11 @@ class _HomePageState extends State<AboutPage> {
_saveCurrentRoute("/AboutPage");
}
@override
void dispose() {
super.dispose();
}
_saveCurrentRoute(String lastRoute) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
await preferences.setString('LastScreenRoute', lastRoute);
@ -24,27 +32,36 @@ class _HomePageState extends State<AboutPage> {
@override
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: AppBar(
title: Text(
"About Page",
style: TextStyle(
fontSize: 30,
color: Colors.black),
return WillPopScope(
onWillPop: () {
if (Navigator.canPop(context)) {
Navigator.of(context).pushNamedAndRemoveUntil(
'/HomePage', (Route<dynamic> route) => true);
} else {
Navigator.of(context).pushReplacementNamed('/HomePage');
}
},
child: PlatformScaffold(
appBar: AppBar(
title: Text(
"About Page",
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
leading: BackButton(),
centerTitle: true,
iconTheme: IconThemeData(color: Colors.black),
),
centerTitle: true,
iconTheme: IconThemeData(color: Colors.black),
elevation: Theme.of(context).platform == TargetPlatform.iOS ? 0.0 : 6.0,
),
drawer: BasicDrawer(),
body: Container(
padding: EdgeInsets.all(32.0),
child: ListView(
body: Container(
padding: EdgeInsets.all(32.0),
child: ListView(
children: <Widget>[
InkWell(
child: const Center(child: Text
('Pear Trading',
style: TextStyle(
style: TextStyle(
fontSize: 20,
color: Colors.blue,
),
@ -113,6 +130,7 @@ class _HomePageState extends State<AboutPage> {
),
),
],
),
),
),
);

View file

@ -1,95 +1,62 @@
import 'package:flutter/material.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:flutter/services.dart';
import 'package:local_spend/common/apifunctions/request_logout_api.dart';
import 'package:local_spend/common/functions/get_token.dart';
import 'package:flutter_fadein/flutter_fadein.dart';
import 'package:local_spend/common/functions/logout.dart';
import 'package:local_spend/pages/receipt_page.dart';
import 'package:local_spend/pages/settings.dart';
class HomePage extends StatelessWidget {
static String _title = 'Text here';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: HomePageWidget(),
);
}
}
class HomePageWidget extends StatefulWidget {
HomePageWidget({Key key}) : super(key: key);
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
class _HomePageState extends State<HomePageWidget> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static List<Widget> _widgetOptions = <Widget>[
ReceiptPage(),
SettingsPage()
];
void initState() {
super.initState();
_saveCurrentRoute("/HomePage");
}
_saveCurrentRoute(String lastRoute) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
await preferences.setString('LastScreenRoute', lastRoute);
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: AppBar(
title: Text(
"Navigation",
style: TextStyle(color: Colors.black),
),
iconTheme: IconThemeData(color: Colors.black),
elevation: Theme.of(context).platform == TargetPlatform.iOS ? 0.0 : 6.0,
return Scaffold(
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
drawer: BasicDrawer(),
body: Container(
padding: EdgeInsets.fromLTRB(0, 15, 0, 0),
child: FadeIn(
duration: Duration(milliseconds: 500),
curve: Curves.easeIn,
child: Column(
children: <Widget>[
ListTile(
title: new Center(
child: new Text(
"Submit Receipt",
style: TextStyle(color: Colors.black, fontSize: 20.0),
textAlign: TextAlign.center,
),
),
onTap: () {
// debugPrint('$token');
Navigator.of(context).pushNamed('/ReceiptPage');
},
),
ListTile(
title: new Center(
child: new Text(
"About",
style: TextStyle(color: Colors.black, fontSize: 20.0),
),
),
onTap: () {
SystemChannels.textInput.invokeMethod('TextInput.hide');
Navigator.of(context).pushReplacementNamed('/AboutPage');
},
),
ListTile(
title: new Center(
child: new Text(
"Logout",
style: TextStyle(color: Colors.black, fontSize: 20.0),
),
),
onTap: () {
logout(context);
},
),
],
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.receipt),
title: Text('Submit Receipt'),
),
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
title: Text('Settings'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.blue[400],
onTap: _onItemTapped,
),
);
}
}
}

View file

@ -19,8 +19,8 @@ class LoginPage extends StatefulWidget {
}
class LoginPageState extends State<LoginPage> {
final TextEditingController _emailController = TextEditingController(/*text: 'test@example.com'*/); // remove
final TextEditingController _passwordController = TextEditingController(/*text: 'abc123'*/); // remove
final TextEditingController _emailController = TextEditingController(text: 'test@example.com'); // remove
final TextEditingController _passwordController = TextEditingController(text: 'abc123'); // remove
bool _saveLoginDetails = true; // I am extremely sorry for the placement of this variable
// it will be fixed soon I promise

View file

@ -9,9 +9,11 @@ import 'package:local_spend/common/widgets/basic_drawer.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:intl/intl.dart';
import 'package:local_spend/pages/settings.dart';
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
import 'package:local_spend/common/apifunctions/find_organisations.dart';
import 'package:local_spend/common/widgets/popupListView.dart';
import 'package:local_spend/common/widgets/labeled_checkbox.dart';
const URL = "https://flutter.io/";
const demonstration = false;
@ -30,6 +32,7 @@ class ReceiptPageState extends State<ReceiptPage> {
final TextEditingController _recurringController = TextEditingController();
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
@ -174,223 +177,310 @@ class ReceiptPageState extends State<ReceiptPage> {
@override
Widget build(BuildContext context) {
var drawer = Drawer();
return WillPopScope(
onWillPop: () {
if (Navigator.canPop(context)) {
Navigator.of(context).pushNamedAndRemoveUntil(
'/HomePage', (Route<dynamic> route) => false);
'/LoginPage', (Route<dynamic> route) => false);
} else {
Navigator.of(context).pushReplacementNamed('/HomePage');
Navigator.of(context).pushReplacementNamed('/LoginPage');
}
},
child: PlatformScaffold(
drawer: BasicDrawer(),
appBar: AppBar(
backgroundColor: Colors.blue[400],
title: Text(
"Submit Receipt",
style: TextStyle(
fontSize: 30.0,
fontSize: 20,
color: Colors.black,
),
),
// leading: BackButton(),
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(
// "Required fields are in bold",
// style: TextStyle(fontSize: 20.0, color: Colors.black),
// ),
// )),
Padding(
padding: EdgeInsets.fromLTRB(0.0,25,0.0,0.0),
child : Text(
"Time of Transaction",
style: TextStyle(
fontSize: 18.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
padding: EdgeInsets.fromLTRB(30.0, 0.0, 30.0, 0.0),
child: ListView(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(0.0,25,0.0,0.0),
child : Text(
"Time of Transaction",
style: TextStyle(
fontSize: 18.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
DateTimePickerFormField(
inputType: InputType.both,
format: DateFormat("dd/MM/yyyy 'at' hh:mm"),
editable: true,
controller: _timeController,
),
DateTimePickerFormField(
inputType: InputType.both,
format: DateFormat("dd/MM/yyyy 'at' hh:mm"),
editable: true,
controller: _timeController,
decoration: InputDecoration(
labelText: 'Date/Time of Transaction', hasFloatingPlaceholder: false),
onChanged: (dt) => setState(() => date = dt),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0,25,0.0,0.0),
child: Text(
"Amount",
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(
controller: _amountController,
decoration: InputDecoration(
labelText: 'Date/Time of Transaction', hasFloatingPlaceholder: false),
onChanged: (dt) => setState(() => date = dt),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0,25,0.0,0.0),
child: Text(
"Amount",
style: TextStyle(
fontSize: 18.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
hintText: 'Value in £',
),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
child: TextField(
controller: _amountController,
decoration: InputDecoration(
hintText: 'Value in £',
),
// obscureText: true,
autocorrect: false,
keyboardType: TextInputType.number,
style: TextStyle(
fontSize: 18.0,
color: Colors.grey[800],
fontWeight: FontWeight.bold,
),
onSubmitted: (_) {
FocusScope.of(context).requestFocus(focusNode);
autocorrect: false,
keyboardType: TextInputType.number,
style: TextStyle(
fontSize: 18.0,
color: Colors.grey[800],
fontWeight: FontWeight.bold,
),
onSubmitted: (_) {
FocusScope.of(context).requestFocus(focusNode);
// submitReceipt(_amountController.text, _timeController.text);
},
),
},
),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0,25,0.0,0.0),
Padding(
padding: EdgeInsets.fromLTRB(0.0,25,0.0,0.0),
child : Container (
height: 22, // this should be the same height as text
child : Container (
height: 22, // this should be the same height as text
child : ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
child : ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(
child: Text(
"Organization Name",
style: TextStyle(
fontSize: 18.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
Container(
child: Text(
"Organization Name",
style: TextStyle(
fontSize: 18.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
Container(
child : Padding(
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
var choice = organisations.then((data) => listOrganisations(data, context));
Container(
child : Padding(
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));
// choice is a Future<String>
},
child: Text("Find",
style:
TextStyle(color: Colors.blue, fontSize: 18.0)),
),
),
)
// choice is a Future<String>
},
child: Text("Find",
style:
TextStyle(color: Colors.blue, fontSize: 18.0)),
),
),
)
],
),
],
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
child: TextField(
controller: _orgController,
focusNode: focusNode,
decoration: InputDecoration(
hintText: 'Eg. Pear Trading',
),
Padding(
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
child: TextField(
controller: _orgController,
focusNode: focusNode,
decoration: InputDecoration(
hintText: 'Eg. Pear Trading',
),
// obscureText: true,
autocorrect: true,
style: TextStyle(
fontSize: 18.0,
color: Colors.grey[800],
fontWeight: FontWeight.bold,
),
onSubmitted: (_) {
submitReceipt(_amountController.text,
_timeController.text, _orgController.text);
// TODO: make sure organisation is valid
// TODO: Add 'find organisation' button which displays a dialog to, well, find the organisation's address or manual entry
autocorrect: true,
style: TextStyle(
fontSize: 18.0,
color: Colors.grey[800],
fontWeight: FontWeight.bold,
),
onSubmitted: (_) {
submitReceipt(_amountController.text,
_timeController.text, _orgController.text);
// TODO: make sure organisation is valid
// TODO: Add 'find organisation' button which displays a dialog to, well, find the organisation's address or manual entry
},
),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0,25,0.0,0.0),
child : Container (
height: 18,
child : ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(
child: Text(
"Essential",
style: TextStyle(
fontSize: 18.0,
color: Colors.black,
),
),
),
Container(
child : Padding(
padding: EdgeInsets.fromLTRB(20.0, 0.0, 0, 0),
child: Checkbox(value:
_essentialController.text.toLowerCase() == 'true',
onChanged: (bool newValue) {
setState(() {
_essentialController.text =
convertBoolToString(newValue);
});
}),
),
),
],
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0,25,0.0,0.0),
child : Container (
height: 27,
// width: 400,
child : ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(
child: Text(
"Recurring",
style: TextStyle(
fontSize: 18.0,
color: Colors.black,
),
),
),
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,
),
),
),
],
),
),
),
// 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(
height: 65.0,
child: RaisedButton(
onPressed: () {
submitReceipt(_amountController.text, _timeController.text, _orgController.text);
},
child: Text("SUBMIT",
style:
TextStyle(color: Colors.white, fontSize: 22.0)),
color: Colors.blue,
),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0,25,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,
),
),
),
Container(
child : Padding(
padding: EdgeInsets.fromLTRB(20.0, 0.0, 0, 0),
child: Checkbox(value:
_essentialController.text.toLowerCase() == 'true',
onChanged: (bool newValue) {
setState(() {
_essentialController.text =
convertBoolToString(newValue);
});
}),
),
),
],
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0, 70.0, 0.0, 0.0),
child: Container(
height: 65.0,
child: RaisedButton(
onPressed: () {
submitReceipt(_amountController.text, _timeController.text, _orgController.text);
},
child: Text("SUBMIT",
style:
TextStyle(color: Colors.white, fontSize: 22.0)),
color: Colors.blue,
),
),
),
],
),
),
],
),
),
),

180
lib/pages/settings.dart Normal file
View file

@ -0,0 +1,180 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:local_spend/common/platform/platform_scaffold.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:local_spend/common/functions/logout.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:local_spend/common/functions/customAbout.dart' as custom;
import 'package:local_spend/common/functions/showDialogTwoButtons.dart';
import 'package:local_spend/common/functions/feedback.dart';
const URL = "https://flutter.io/";
const demonstration = false;
class SettingsPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new SettingsPageState();
}
}
class SettingsPageState extends State<SettingsPage> {
FocusNode focusNode; // added so focus can move automatically
DateTime date;
@override
void initState() {
super.initState();
_saveCurrentRoute("/SettingsPageState");
focusNode = FocusNode();
}
@override
void dispose() {
super.dispose();
focusNode.dispose(); //disposes focus node when form disposed
}
_saveCurrentRoute(String lastRoute) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
await preferences.setString('LastPageRoute', lastRoute);
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
if (Navigator.canPop(context)) {
Navigator.of(context).pushNamedAndRemoveUntil(
'/LoginPage', (Route<dynamic> route) => false);
} else {
Navigator.of(context).pushReplacementNamed('/LoginPage');
}
},
child: PlatformScaffold(
appBar: AppBar(
backgroundColor: Colors.blue[400],
title: Text(
"Settings",
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
// leading: BackButton(),
centerTitle: true,
iconTheme: IconThemeData(color: Colors.black),
),
body: Container(
padding: EdgeInsets.fromLTRB(30.0, 0.0, 30.0, 0.0),
child: ListView(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(0.0,25,0.0,0.0),
child : Text(
"Local Spend Tracker",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
//
// Padding(
// padding: EdgeInsets.fromLTRB(10, 15, 0, 0),
// child: Text("helloooo"),
// ),
Padding(
padding: EdgeInsets.fromLTRB(0.0, 25.0, 0.0, 0.0),
child: Container(
height: 65.0,
child: RaisedButton(
onPressed: () {
custom.showAboutDialog(
context: context,
applicationIcon: new Icon(Icons.receipt),
applicationName: "Local Spend Tracker",
children: <Widget> [
Text("Pear Trading is a commerce company designed to register and monitor money circulating in the local economy."),
Text("\nContact at test@example.com or +44(0)1524 64544"),
Padding(
padding: EdgeInsets.fromLTRB(0,20,0,0),
child: InkWell(
child: Text
('Developed by Shadowcat Systems',
style: TextStyle(
color: Colors.blue,
),
),
onTap: () => launch('https://shadow.cat/')
),
),
],
);
},
child: Text("ABOUT",
style:
TextStyle(color: Colors.white, fontSize: 22.0)),
color: Colors.blue,
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 0.0),
child: Container(
height: 65.0,
child: RaisedButton(
onPressed: () {
showDialogTwoButtons(
context,
"Logout",
"Are you sure you want to log out?",
"Cancel",
"Logout",
logout
);
},
child: Text("LOGOUT",
style:
TextStyle(color: Colors.white, fontSize: 22.0)),
color: Colors.red,
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 0.0),
child: Container(
height: 65.0,
child: RaisedButton(
onPressed: () {
feedback(context);
},
child: Text("FEEDBACK",
style:
TextStyle(color: Colors.white, fontSize: 22.0)),
color: Colors.green,
),
),
),
],
),
),
),
);
}
}