From c5cf66a2107c436c3399477fb038a21ffd246d67 Mon Sep 17 00:00:00 2001 From: Felix Date: Tue, 16 Jul 2019 15:12:16 +0100 Subject: [PATCH] Changed navigation a bit, added 'stats' section sections are easy to add and remove --- lib/main.dart | 4 +- lib/pages/home_page.dart | 10 +++- lib/pages/{settings.dart => more_page.dart} | 8 +-- lib/pages/receipt_page.dart | 10 ++-- lib/pages/stats_page.dart | 66 +++++++++++++++++++++ pubspec.lock | 10 ++-- 6 files changed, 91 insertions(+), 17 deletions(-) rename lib/pages/{settings.dart => more_page.dart} (96%) create mode 100644 lib/pages/stats_page.dart diff --git a/lib/main.dart b/lib/main.dart index 9354be8..a4a84be 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,7 +3,7 @@ import 'package:local_spend/pages/home_page.dart'; import 'package:local_spend/pages/login_page.dart'; import 'package:local_spend/pages/receipt_page.dart'; import 'package:local_spend/pages/spash_screen.dart'; -import 'package:local_spend/pages/settings.dart'; +import 'package:local_spend/pages/more_page.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; void main() { @@ -32,7 +32,7 @@ class MyApp extends StatelessWidget { "/HomePage": (BuildContext context) => HomePage(), "/LoginPage": (BuildContext context) => LoginPage(), "/ReceiptPage": (BuildContext context) => ReceiptPage(), - "/SettingsPage": (BuildContext context) => SettingsPage(), + "/MorePage": (BuildContext context) => MorePage(), }, home: SplashScreen(), ); diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index d3547f4..bad8709 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:local_spend/pages/receipt_page.dart'; -import 'package:local_spend/pages/settings.dart'; +import 'package:local_spend/pages/more_page.dart'; +import 'package:local_spend/pages/stats_page.dart'; class HomePage extends StatelessWidget { static String _title = 'Text here'; @@ -27,7 +28,8 @@ class _HomePageState extends State { TextStyle(fontSize: 30, fontWeight: FontWeight.bold); static List _widgetOptions = [ ReceiptPage(), - SettingsPage() + StatsPage(), + MorePage() ]; void _onItemTapped(int index) { @@ -48,6 +50,10 @@ class _HomePageState extends State { icon: Icon(Icons.receipt), title: Text('Submit Receipt'), ), + BottomNavigationBarItem( + icon: Icon(Icons.show_chart), + title: Text('Statistics'), + ), BottomNavigationBarItem( icon: Icon(Icons.more_horiz), title: Text('More'), diff --git a/lib/pages/settings.dart b/lib/pages/more_page.dart similarity index 96% rename from lib/pages/settings.dart rename to lib/pages/more_page.dart index ebdc4b2..21814de 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/more_page.dart @@ -10,14 +10,14 @@ import 'package:local_spend/common/functions/showDialogTwoButtons.dart'; const URL = "https://flutter.io/"; const demonstration = false; -class SettingsPage extends StatefulWidget { +class MorePage extends StatefulWidget { @override State createState() { - return new SettingsPageState(); + return new MorePageState(); } } -class SettingsPageState extends State { +class MorePageState extends State { FocusNode focusNode; // added so focus can move automatically DateTime date; @@ -25,7 +25,7 @@ class SettingsPageState extends State { @override void initState() { super.initState(); - _saveCurrentRoute("/SettingsPageState"); + _saveCurrentRoute("/MorePageState"); focusNode = FocusNode(); } diff --git a/lib/pages/receipt_page.dart b/lib/pages/receipt_page.dart index 94bbfd9..0c5e381 100644 --- a/lib/pages/receipt_page.dart +++ b/lib/pages/receipt_page.dart @@ -31,7 +31,7 @@ class ReceiptPageState extends State { final TextEditingController _orgController = TextEditingController(); final OrganizationController _organizationController = OrganizationController(); - FocusNode focusNode; // added so focus can move automatically + FocusNode focusNode; DateTime date; @@ -55,6 +55,7 @@ class ReceiptPageState extends State { focusNode = FocusNode(); _recurringController.text = "None"; + _categoryController.text = ""; } @override @@ -71,7 +72,7 @@ class ReceiptPageState extends State { // this file is getting really messy sorry everyone - void submitReceipt(String amount, String time, Organisation organisation, String recurring) async { + void submitReceipt(String amount, String time, Organisation organisation, String recurring, String category) async { SystemChannels.textInput.invokeMethod('TextInput.hide'); if (organisation == null) { @@ -154,6 +155,7 @@ class ReceiptPageState extends State { receipt.town = organisation.town; receipt.postcode = organisation.postcode; receipt.recurring = recurring; + receipt.category = category; // receipt.essential = convertBoolToString(toConvert) @@ -414,7 +416,7 @@ class ReceiptPageState extends State { ), onSubmitted: (_) { submitReceipt(_amountController.text, - _timeController.text, _organizationController.organisation, _recurringController.text); + _timeController.text, _organizationController.organisation, _recurringController.text, _categoryController.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 }, @@ -515,7 +517,7 @@ class ReceiptPageState extends State { try { submitReceipt( _amountController.text, _timeController.text, - _organizationController.organisation, _recurringController.text); + _organizationController.organisation, _recurringController.text, _categoryController.text); } catch (_) { showDialog( diff --git a/lib/pages/stats_page.dart b/lib/pages/stats_page.dart new file mode 100644 index 0000000..adcbdb4 --- /dev/null +++ b/lib/pages/stats_page.dart @@ -0,0 +1,66 @@ + +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'; + +const URL = "https://flutter.io/"; +const demonstration = false; + +class StatsPage extends StatefulWidget { + @override + State createState() { + return new StatsPageState(); + } +} + +class StatsPageState extends State { + + @override + void initState() { + super.initState(); + _saveCurrentRoute("/StatsPageState"); + } + + @override + void dispose() { + super.dispose(); + } + + _saveCurrentRoute(String lastRoute) async { + SharedPreferences preferences = await SharedPreferences.getInstance(); + await preferences.setString('LastPageRoute', lastRoute); + } + + @override + Widget build(BuildContext context) { + return PlatformScaffold( + appBar: AppBar( + backgroundColor: Colors.blue[400], + title: Text( + "Statistics", + style: TextStyle( + fontSize: 20, + color: Colors.white, + ), + ), +// leading: BackButton(), + centerTitle: true, + iconTheme: IconThemeData(color: Colors.black), + ), + + body: Container( + padding: EdgeInsets.fromLTRB(0, 15, 0, 0), + child: Column( + children: [ + // some graphs and charts here etc + Center(child : Text("(imagine this is a really cool graph!)"),) + ], + ), + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index a1721f3..b229dc3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,5 +1,5 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: analyzer: dependency: transitive @@ -21,7 +21,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" boolean_selector: dependency: transitive description: @@ -330,7 +330,7 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.5.0" + version: "1.7.0" pool: dependency: transitive description: @@ -358,7 +358,7 @@ packages: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.3" shared_preferences: dependency: "direct main" description: @@ -440,7 +440,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.4" + version: "0.2.5" timing: dependency: transitive description: