From 7b640f104b5b53852b32d36b315d5757ff14b948 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 11:57:19 +0100 Subject: [PATCH 01/23] Move ToBeBudgeted widget to separate file --- lib/screens/budget/budgetPage.dart | 37 +---------------- .../budget/components/toBeBudgeted.dart | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 lib/screens/budget/components/toBeBudgeted.dart diff --git a/lib/screens/budget/budgetPage.dart b/lib/screens/budget/budgetPage.dart index d1a82575..606908ec 100644 --- a/lib/screens/budget/budgetPage.dart +++ b/lib/screens/budget/budgetPage.dart @@ -9,6 +9,7 @@ import 'package:your_budget/screens/budget/budgetPageState.dart'; import 'package:your_budget/screens/budget/components/MainCategoryRow.dart'; import 'package:your_budget/screens/budget/components/SubCategoryRow.dart'; import 'package:your_budget/screens/budget/components/buttonDial.dart'; +import 'package:your_budget/screens/budget/components/toBeBudgeted.dart'; import 'package:provider/provider.dart'; class BudgetPage extends StatefulWidget { @@ -73,7 +74,7 @@ class _BudgetPageState extends State { ), body: Column(children: [ _DateButtons(), // - _ToBeBudgeted(), + ToBeBudgeted(), Expanded(child: _CategoriesList()), buttonDialState.showButtonDial @@ -125,40 +126,6 @@ class __CategoriesListState extends State<_CategoriesList> { } } -class _ToBeBudgeted extends StatelessWidget { - final TextStyle _textStyle = - TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 25.0); - - final TextStyle _positiveAmountTextStyle = - new TextStyle(color: Constants.GREEN_COLOR, fontSize: 32.0); - final TextStyle _negativeAmountTextStyle = - new TextStyle(color: Constants.RED_COLOR, fontSize: 32.0); - - @override - Widget build(BuildContext context) { - return Container( - height: 50, - child: Row( - children: [ - Expanded( - child: Text( - "To be budgeted", - style: _textStyle, - )), - Consumer( - builder: (context, appState, child) { - return Text( - appState.toBeBudgeted.toStringAsFixed(2) + " €" ?? "0.00" + " €", - style: appState.toBeBudgeted >= 0 - ? _positiveAmountTextStyle - : _negativeAmountTextStyle, - ); - }, - ) - ], - )); - } -} class _DateButtons extends StatelessWidget { void handleButtonOnPressed(BuildContext context, AppState appState, bool increment) { diff --git a/lib/screens/budget/components/toBeBudgeted.dart b/lib/screens/budget/components/toBeBudgeted.dart new file mode 100644 index 00000000..2c10c148 --- /dev/null +++ b/lib/screens/budget/components/toBeBudgeted.dart @@ -0,0 +1,40 @@ + +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:your_budget/appState.dart'; +import 'package:your_budget/models/constants.dart'; + +class ToBeBudgeted extends StatelessWidget { + final TextStyle _textStyle = + TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 25.0); + + final TextStyle _positiveAmountTextStyle = + new TextStyle(color: Constants.GREEN_COLOR, fontSize: 32.0); + final TextStyle _negativeAmountTextStyle = + new TextStyle(color: Constants.RED_COLOR, fontSize: 32.0); + + @override + Widget build(BuildContext context) { + return Container( + height: 50, + child: Row( + children: [ + Expanded( + child: Text( + "To be budgeted", + style: _textStyle, + )), + Consumer( + builder: (context, appState, child) { + return Text( + appState.toBeBudgeted.toStringAsFixed(2) + " €" ?? "0.00" + " €", + style: appState.toBeBudgeted >= 0 + ? _positiveAmountTextStyle + : _negativeAmountTextStyle, + ); + }, + ) + ], + )); + } +} From a62fca251b5b64c492bab283089858d7d30a872a Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 12:00:03 +0100 Subject: [PATCH 02/23] Move DateButtons widget to separate file --- lib/screens/budget/budgetPage.dart | 32 ++--------------- .../budget/components/dateButtons.dart | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 30 deletions(-) create mode 100644 lib/screens/budget/components/dateButtons.dart diff --git a/lib/screens/budget/budgetPage.dart b/lib/screens/budget/budgetPage.dart index 606908ec..4c2078dc 100644 --- a/lib/screens/budget/budgetPage.dart +++ b/lib/screens/budget/budgetPage.dart @@ -10,6 +10,7 @@ import 'package:your_budget/screens/budget/components/MainCategoryRow.dart'; import 'package:your_budget/screens/budget/components/SubCategoryRow.dart'; import 'package:your_budget/screens/budget/components/buttonDial.dart'; import 'package:your_budget/screens/budget/components/toBeBudgeted.dart'; +import 'package:your_budget/screens/budget/components/dateButtons.dart'; import 'package:provider/provider.dart'; class BudgetPage extends StatefulWidget { @@ -73,7 +74,7 @@ class _BudgetPageState extends State { ], ), body: Column(children: [ - _DateButtons(), // + DateButtons(), // ToBeBudgeted(), Expanded(child: _CategoriesList()), @@ -125,32 +126,3 @@ class __CategoriesListState extends State<_CategoriesList> { ); } } - - -class _DateButtons extends StatelessWidget { - void handleButtonOnPressed(BuildContext context, AppState appState, bool increment) { - increment ? appState.incrementMonth() : appState.decrementMonth(); - BudgetPageState buttonDialState = Provider.of(context, listen: false); - buttonDialState.toggleButtonDial(-1); - } - - @override - Widget build(BuildContext context) { - return Consumer(builder: (_, appState, __) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - IconButton( - icon: Icon(Icons.arrow_back), - onPressed: () => handleButtonOnPressed(context, appState, false)), - Text("${appState.currentBudget.monthAsString} ${appState.currentBudget.year}", - style: TextStyle(fontSize: 20)), - IconButton( - icon: Icon(Icons.arrow_forward), - onPressed: () => handleButtonOnPressed(context, appState, true)) - ], - ); - }); - } -} diff --git a/lib/screens/budget/components/dateButtons.dart b/lib/screens/budget/components/dateButtons.dart new file mode 100644 index 00000000..4a2cac7f --- /dev/null +++ b/lib/screens/budget/components/dateButtons.dart @@ -0,0 +1,34 @@ + + +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:your_budget/appState.dart'; +import 'package:your_budget/screens/budget/budgetPageState.dart'; + +class DateButtons extends StatelessWidget { + void handleButtonOnPressed(BuildContext context, AppState appState, bool increment) { + increment ? appState.incrementMonth() : appState.decrementMonth(); + BudgetPageState buttonDialState = Provider.of(context, listen: false); + buttonDialState.toggleButtonDial(-1); + } + + @override + Widget build(BuildContext context) { + return Consumer(builder: (_, appState, __) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + IconButton( + icon: Icon(Icons.arrow_back), + onPressed: () => handleButtonOnPressed(context, appState, false)), + Text("${appState.currentBudget.monthAsString} ${appState.currentBudget.year}", + style: TextStyle(fontSize: 20)), + IconButton( + icon: Icon(Icons.arrow_forward), + onPressed: () => handleButtonOnPressed(context, appState, true)) + ], + ); + }); + } +} From fedcc4db17242517322ad2536198406256b2d6ee Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 12:10:29 +0100 Subject: [PATCH 03/23] Move CategoriesList widget to separate file --- lib/screens/budget/budgetPage.dart | 48 +------------------ .../budget/components/categoriesList.dart | 44 +++++++++++++++++ 2 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 lib/screens/budget/components/categoriesList.dart diff --git a/lib/screens/budget/budgetPage.dart b/lib/screens/budget/budgetPage.dart index 4c2078dc..30ec375e 100644 --- a/lib/screens/budget/budgetPage.dart +++ b/lib/screens/budget/budgetPage.dart @@ -1,16 +1,13 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:your_budget/appState.dart'; -import 'package:your_budget/models/categories.dart'; import 'package:your_budget/models/constants.dart'; import 'package:your_budget/screens/modifyCategories/ModifyCategories.dart'; import 'package:your_budget/screens/about/aboutScreen.dart'; import 'package:your_budget/screens/budget/budgetPageState.dart'; -import 'package:your_budget/screens/budget/components/MainCategoryRow.dart'; -import 'package:your_budget/screens/budget/components/SubCategoryRow.dart'; import 'package:your_budget/screens/budget/components/buttonDial.dart'; import 'package:your_budget/screens/budget/components/toBeBudgeted.dart'; import 'package:your_budget/screens/budget/components/dateButtons.dart'; +import 'package:your_budget/screens/budget/components/categoriesList.dart'; import 'package:provider/provider.dart'; class BudgetPage extends StatefulWidget { @@ -76,7 +73,7 @@ class _BudgetPageState extends State { body: Column(children: [ DateButtons(), // ToBeBudgeted(), - Expanded(child: _CategoriesList()), + Expanded(child: CategoriesList()), buttonDialState.showButtonDial ? ButtonDial( @@ -85,44 +82,3 @@ class _BudgetPageState extends State { ])); } } - -class _CategoriesList extends StatefulWidget { - @override - __CategoriesListState createState() => __CategoriesListState(); -} - -class __CategoriesListState extends State<_CategoriesList> { - final ScrollController _scrollController = ScrollController(); - - @override - void dispose() { - _scrollController.dispose(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - final AppState appState = Provider.of(context); - final List categories = appState.allCategories; - - if (categories.isEmpty) { - return Center( - child: CircularProgressIndicator(), - ); - } - return Scrollbar( - isAlwaysShown: true, - controller: _scrollController, - child: ListView.separated( - controller: _scrollController, - itemCount: categories.length, - separatorBuilder: (BuildContext context, int index) => - Divider(height: 1, color: Colors.black12), - itemBuilder: (context, index) { - var item = categories[index]; - return (item is MainCategory) ? MainCategoryRow(cat: item) : SubcategoryRow(subcat: item); - }, - ), - ); - } -} diff --git a/lib/screens/budget/components/categoriesList.dart b/lib/screens/budget/components/categoriesList.dart new file mode 100644 index 00000000..b5f53aa4 --- /dev/null +++ b/lib/screens/budget/components/categoriesList.dart @@ -0,0 +1,44 @@ + +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:your_budget/appState.dart'; +import 'package:your_budget/models/categories.dart'; +import 'package:your_budget/screens/budget/components/MainCategoryRow.dart'; +import 'package:your_budget/screens/budget/components/SubCategoryRow.dart'; + +class CategoriesList extends StatefulWidget { + @override + _CategoriesListState createState() => _CategoriesListState(); +} + +class _CategoriesListState extends State { + final ScrollController _scrollController = ScrollController(); + + + @override + void dispose() { + _scrollController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final AppState appState = Provider.of(context); + final List categories = appState.allCategories; + + return Scrollbar( + isAlwaysShown: true, + controller: _scrollController, + child: ListView.separated( + controller: _scrollController, + itemCount: categories.length, + separatorBuilder: (BuildContext context, int index) => + Divider(height: 1, color: Colors.black12), + itemBuilder: (context, index) { + var item = categories[index]; + return (item is MainCategory) ? MainCategoryRow(cat: item) : SubcategoryRow(subcat: item); + }, + ), + ); + } +} From cd5b05f084f6106cd0f6fc183be5e27205038f1e Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 12:18:53 +0100 Subject: [PATCH 04/23] Move buttonDial logic out of build tree --- lib/screens/budget/budgetPage.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/screens/budget/budgetPage.dart b/lib/screens/budget/budgetPage.dart index 30ec375e..789cccc0 100644 --- a/lib/screens/budget/budgetPage.dart +++ b/lib/screens/budget/budgetPage.dart @@ -40,6 +40,10 @@ class _BudgetPageState extends State { @override Widget build(BuildContext context) { BudgetPageState buttonDialState = Provider.of(context); + ButtonDial buttonDial = buttonDialState.showButtonDial + ? ButtonDial( + MediaQuery.of(context).size.height * 0.3, MediaQuery.of(context).size.width * 0.6) : null; + print("Budget page build"); return Scaffold( appBar: AppBar( @@ -74,11 +78,7 @@ class _BudgetPageState extends State { DateButtons(), // ToBeBudgeted(), Expanded(child: CategoriesList()), - - buttonDialState.showButtonDial - ? ButtonDial( - MediaQuery.of(context).size.height * 0.3, MediaQuery.of(context).size.width * 0.6) - : ButtonDial(0, 0), + if(buttonDial != null) buttonDial ])); } } From 6a31d6afd887d60cee7e280098a52d31a5ca637c Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 12:19:09 +0100 Subject: [PATCH 05/23] Format budgetPage.dart --- lib/screens/budget/budgetPage.dart | 33 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/screens/budget/budgetPage.dart b/lib/screens/budget/budgetPage.dart index 789cccc0..68fd4d18 100644 --- a/lib/screens/budget/budgetPage.dart +++ b/lib/screens/budget/budgetPage.dart @@ -23,8 +23,7 @@ class _BudgetPageState extends State { bool showMenu = true; //TODO: Settings - void handleSettings() { - } + void handleSettings() {} void handlePopUpMenuButtonSelected(String selectedItem) async { if (selectedItem == "About") { @@ -34,15 +33,17 @@ class _BudgetPageState extends State { } void handleModifyCategories() { - Navigator.push(context, MaterialPageRoute(builder: (context) => ModifyCategories())); + Navigator.push( + context, MaterialPageRoute(builder: (context) => ModifyCategories())); } @override Widget build(BuildContext context) { BudgetPageState buttonDialState = Provider.of(context); - ButtonDial buttonDial = buttonDialState.showButtonDial - ? ButtonDial( - MediaQuery.of(context).size.height * 0.3, MediaQuery.of(context).size.width * 0.6) : null; + ButtonDial buttonDial = buttonDialState.showButtonDial + ? ButtonDial(MediaQuery.of(context).size.height * 0.3, + MediaQuery.of(context).size.width * 0.6) + : null; print("Budget page build"); return Scaffold( @@ -60,15 +61,15 @@ class _BudgetPageState extends State { icon: Icon(FontAwesomeIcons.checkSquare), onPressed: handleModifyCategories, ), - PopupMenuButton( - onSelected: handlePopUpMenuButtonSelected, - itemBuilder: (context) => [ - PopupMenuItem( - value: "About", - child: Text("About"), - ), - ], - ), + PopupMenuButton( + onSelected: handlePopUpMenuButtonSelected, + itemBuilder: (context) => [ + PopupMenuItem( + value: "About", + child: Text("About"), + ), + ], + ), ], ), ) @@ -78,7 +79,7 @@ class _BudgetPageState extends State { DateButtons(), // ToBeBudgeted(), Expanded(child: CategoriesList()), - if(buttonDial != null) buttonDial + if (buttonDial != null) buttonDial ])); } } From f6844498af2ddf122c2663c5039db96467cfac76 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 12:20:21 +0100 Subject: [PATCH 06/23] Instantiate scrollController in initState --- lib/screens/budget/components/categoriesList.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/screens/budget/components/categoriesList.dart b/lib/screens/budget/components/categoriesList.dart index b5f53aa4..c8ff8de6 100644 --- a/lib/screens/budget/components/categoriesList.dart +++ b/lib/screens/budget/components/categoriesList.dart @@ -12,8 +12,13 @@ class CategoriesList extends StatefulWidget { } class _CategoriesListState extends State { - final ScrollController _scrollController = ScrollController(); + ScrollController _scrollController; + @override + void initState() { + super.initState(); + _scrollController = ScrollController(); + } @override void dispose() { From f503fba52fac9cdb2c4153d5bd40354523ecdf48 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 12:38:39 +0100 Subject: [PATCH 07/23] Use SingleChildScrollView instead of ListView --- .../budget/components/categoriesList.dart | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/screens/budget/components/categoriesList.dart b/lib/screens/budget/components/categoriesList.dart index c8ff8de6..e85ebca2 100644 --- a/lib/screens/budget/components/categoriesList.dart +++ b/lib/screens/budget/components/categoriesList.dart @@ -1,4 +1,3 @@ - import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:your_budget/appState.dart'; @@ -28,22 +27,30 @@ class _CategoriesListState extends State { @override Widget build(BuildContext context) { - final AppState appState = Provider.of(context); - final List categories = appState.allCategories; - return Scrollbar( - isAlwaysShown: true, - controller: _scrollController, - child: ListView.separated( + isAlwaysShown: true, controller: _scrollController, - itemCount: categories.length, - separatorBuilder: (BuildContext context, int index) => - Divider(height: 1, color: Colors.black12), - itemBuilder: (context, index) { - var item = categories[index]; - return (item is MainCategory) ? MainCategoryRow(cat: item) : SubcategoryRow(subcat: item); - }, - ), - ); + child: SingleChildScrollView( + controller: _scrollController, + child: Consumer( + builder: (_, appState, __) => + Column(children: _buildList(appState))))); + } +} + +List _buildList(AppState appState) { + List categories = appState.allCategories; + List widgetList = []; + + Divider divider = Divider(height: 1, color: Colors.black12); + + for (final Category category in categories) { + var categoryWidget = (category is MainCategory) + ? MainCategoryRow(cat: category) + : SubcategoryRow(subcat: category); + widgetList.add(categoryWidget); + widgetList.add(divider); } + + return widgetList; } From 891f63e114e52d8ceafcb2da5385b6d8c8145fa5 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 12:38:39 +0100 Subject: [PATCH 08/23] Use SingleChildScrollView instead of ListView --- .../budget/components/categoriesList.dart | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/screens/budget/components/categoriesList.dart b/lib/screens/budget/components/categoriesList.dart index c8ff8de6..1db9be7f 100644 --- a/lib/screens/budget/components/categoriesList.dart +++ b/lib/screens/budget/components/categoriesList.dart @@ -1,4 +1,3 @@ - import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:your_budget/appState.dart'; @@ -28,22 +27,34 @@ class _CategoriesListState extends State { @override Widget build(BuildContext context) { - final AppState appState = Provider.of(context); - final List categories = appState.allCategories; - return Scrollbar( isAlwaysShown: true, controller: _scrollController, - child: ListView.separated( + child: SingleChildScrollView( controller: _scrollController, - itemCount: categories.length, - separatorBuilder: (BuildContext context, int index) => - Divider(height: 1, color: Colors.black12), - itemBuilder: (context, index) { - var item = categories[index]; - return (item is MainCategory) ? MainCategoryRow(cat: item) : SubcategoryRow(subcat: item); - }, + child: Consumer( + builder: (_, appState, __) => Column( + children: _buildList(appState), + ), + ), ), ); } } + +List _buildList(AppState appState) { + List categories = appState.allCategories; + List widgetList = []; + + Divider divider = Divider(height: 1, color: Colors.black12); + + for (final Category category in categories) { + var categoryWidget = (category is MainCategory) + ? MainCategoryRow(cat: category) + : SubcategoryRow(subcat: category); + widgetList.add(categoryWidget); + widgetList.add(divider); + } + + return widgetList; +} From b5dd49f7c3277b532e91efa875c773917e2c2f81 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 18:00:53 +0100 Subject: [PATCH 09/23] Sort payees by name #31 --- lib/screens/addTransaction/selectValue.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/screens/addTransaction/selectValue.dart b/lib/screens/addTransaction/selectValue.dart index 730692ed..56278b5d 100644 --- a/lib/screens/addTransaction/selectValue.dart +++ b/lib/screens/addTransaction/selectValue.dart @@ -132,6 +132,10 @@ class SelectValuePageState extends State { } else listEntries = widget.listEntries; + if (isPayee){ + listEntries.sort((a, b) => a.name.compareTo(b.name)); + } + return Scaffold( resizeToAvoidBottomInset: false, appBar: AppBar( From 1b8ff3b54d70e791506845e0deb5a4e11bf75eea Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 18:04:23 +0100 Subject: [PATCH 10/23] Create MOST_RECENT_ACCOUNT constant in database #32 --- lib/models/database_provider.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/models/database_provider.dart b/lib/models/database_provider.dart index a463b1e0..6384e894 100644 --- a/lib/models/database_provider.dart +++ b/lib/models/database_provider.dart @@ -209,5 +209,9 @@ class DatabaseProvider { String maxBudgetDateMillisecondsSinceEpoch = getMaxBudgetDate().millisecondsSinceEpoch.toString(); db.rawInsert(CREATE_CONSTANT, ["MAX_BUDGET_DATE", maxBudgetDateMillisecondsSinceEpoch]); + + ///Save account most recently used. + db.rawInsert(CREATE_CONSTANT, ["MOST_RECENT_ACCOUNT", 0]); + } } From 5f47681989979ee543f34d04dd6ccc22985e30d1 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 18:12:52 +0100 Subject: [PATCH 11/23] Implement method updating last used account #32 --- lib/models/SQLQueries.dart | 15 +++++++++++++++ lib/models/queries.dart | 2 ++ 2 files changed, 17 insertions(+) diff --git a/lib/models/SQLQueries.dart b/lib/models/SQLQueries.dart index 86316195..5e65a429 100644 --- a/lib/models/SQLQueries.dart +++ b/lib/models/SQLQueries.dart @@ -499,4 +499,19 @@ class SQLQueryClass implements Queries{ final result = await database.rawUpdate(sql, params); DatabaseProvider.databaseLog('Update maxBudgetDate', sql, null, result, params); } + + @override + Future updateMostRecentAccountUsed(int accountId) async{ + // TODO: implement setMostRecentAccountUsed + + final sql = '''UPDATE ${DatabaseConstants.constantsTable} + SET ${DatabaseConstants.CONSTANT_VALUE} = ? + WHERE ${DatabaseConstants.CONSTANT_NAME} == 'MOST_RECENT_ACCOUNT' + ;'''; + + List params = [accountId]; + final result = await database.rawUpdate(sql, params); + DatabaseProvider.databaseLog('Update most recent account used', sql, null, result, params); + + } } diff --git a/lib/models/queries.dart b/lib/models/queries.dart index 595dd30d..414e795f 100644 --- a/lib/models/queries.dart +++ b/lib/models/queries.dart @@ -142,4 +142,6 @@ abstract class Queries { Future setMaxBudgetDateConstant(DateTime newMaxBudgetDate); + Future updateMostRecentAccountUsed(int accountId); + } From 044f777cf904af16f32b5d7b2593c3f2e9dc9503 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 18:29:33 +0100 Subject: [PATCH 12/23] Use DatabaseConstants instead of strings #32 --- lib/models/SQLQueries.dart | 8 ++++---- lib/models/constants.dart | 6 ++++++ lib/models/database_provider.dart | 9 +++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/models/SQLQueries.dart b/lib/models/SQLQueries.dart index 5e65a429..42aaca47 100644 --- a/lib/models/SQLQueries.dart +++ b/lib/models/SQLQueries.dart @@ -473,7 +473,7 @@ class SQLQueryClass implements Queries{ Future getStartingBudgetDateConstant() async { final sql = '''SELECT ${DatabaseConstants.CONSTANT_VALUE} FROM ${DatabaseConstants.constantsTable} - WHERE ${DatabaseConstants.CONSTANT_NAME} == 'STARTING_BUDGET_DATE';'''; + WHERE ${DatabaseConstants.CONSTANT_NAME} == ${DatabaseConstants.STARTING_BUDGET_DATE};'''; final data = await database.rawQuery(sql); int startingBudgetDateMillisecondsSinceEpoch = int.parse(data[0]['value'].toString()); @@ -482,7 +482,7 @@ class SQLQueryClass implements Queries{ Future getMaxBudgetDateConstant() async { final sql = '''SELECT ${DatabaseConstants.CONSTANT_VALUE} FROM ${DatabaseConstants.constantsTable} - WHERE ${DatabaseConstants.CONSTANT_NAME} == 'MAX_BUDGET_DATE';'''; + WHERE ${DatabaseConstants.CONSTANT_NAME} == ${DatabaseConstants.MAX_BUDGET_DATE};'''; final data = await database.rawQuery(sql); int maxBudgetDateMillisecondsSinceEpoch = int.parse(data[0]['value'].toString()); @@ -492,7 +492,7 @@ class SQLQueryClass implements Queries{ Future setMaxBudgetDateConstant(DateTime newMaxBudgetDate) async { final sql = '''UPDATE ${DatabaseConstants.constantsTable} SET ${DatabaseConstants.CONSTANT_VALUE} = ? - WHERE ${DatabaseConstants.CONSTANT_NAME} == 'MAX_BUDGET_DATE' + WHERE ${DatabaseConstants.CONSTANT_NAME} == ${DatabaseConstants.MAX_BUDGET_DATE} ;'''; List params = [newMaxBudgetDate.millisecondsSinceEpoch]; @@ -506,7 +506,7 @@ class SQLQueryClass implements Queries{ final sql = '''UPDATE ${DatabaseConstants.constantsTable} SET ${DatabaseConstants.CONSTANT_VALUE} = ? - WHERE ${DatabaseConstants.CONSTANT_NAME} == 'MOST_RECENT_ACCOUNT' + WHERE ${DatabaseConstants.CONSTANT_NAME} == ${DatabaseConstants.MOST_RECENT_ACCOUNT} ;'''; List params = [accountId]; diff --git a/lib/models/constants.dart b/lib/models/constants.dart index 7e5be73e..642bac0b 100644 --- a/lib/models/constants.dart +++ b/lib/models/constants.dart @@ -88,4 +88,10 @@ class DatabaseConstants { static const String BUDGET_VALUE_OUTSIDE = 'budgetvalues_id'; static const String GOAL_ID_OUTSIDE = 'goal_id'; + + /// Constants + static const String STARTING_BUDGET_DATE = "STARTING_BUDGET_DATE"; + static const String MAX_BUDGET_DATE = "MAX_BUDGET_DATE"; + static const String MOST_RECENT_ACCOUNT = "MOST_RECENT_ACCOUNT"; + } diff --git a/lib/models/database_provider.dart b/lib/models/database_provider.dart index 6384e894..cb02beec 100644 --- a/lib/models/database_provider.dart +++ b/lib/models/database_provider.dart @@ -203,12 +203,17 @@ class DatabaseProvider { /// Create the starting budget date based on the first time the user uses the app String startingDateMillisecondsSinceEpoch = getDateYMD(DateTime.now()).millisecondsSinceEpoch.toString(); - db.rawInsert(CREATE_CONSTANT, ["STARTING_BUDGET_DATE", startingDateMillisecondsSinceEpoch]); + db.rawInsert(CREATE_CONSTANT, [DatabaseConstants.STARTING_BUDGET_DATE, startingDateMillisecondsSinceEpoch]); /// Create the maximum budget date based on current date + Constants.MAX_NB_MONTHS_AHEAD String maxBudgetDateMillisecondsSinceEpoch = getMaxBudgetDate().millisecondsSinceEpoch.toString(); - db.rawInsert(CREATE_CONSTANT, ["MAX_BUDGET_DATE", maxBudgetDateMillisecondsSinceEpoch]); + db.rawInsert(CREATE_CONSTANT, [DatabaseConstants.MAX_BUDGET_DATE, maxBudgetDateMillisecondsSinceEpoch]); + + ///Save account most recently used. + db.rawInsert(CREATE_CONSTANT, [DatabaseConstants.MOST_RECENT_ACCOUNT, 0]); + + } ///Save account most recently used. db.rawInsert(CREATE_CONSTANT, ["MOST_RECENT_ACCOUNT", 0]); From a231d3af009924cb121b484fc767464e9690d37b Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 18:32:47 +0100 Subject: [PATCH 13/23] Save most recent account id as string #32 --- lib/models/SQLQueries.dart | 2 +- lib/models/database_provider.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/models/SQLQueries.dart b/lib/models/SQLQueries.dart index 42aaca47..b3c3bb59 100644 --- a/lib/models/SQLQueries.dart +++ b/lib/models/SQLQueries.dart @@ -509,7 +509,7 @@ class SQLQueryClass implements Queries{ WHERE ${DatabaseConstants.CONSTANT_NAME} == ${DatabaseConstants.MOST_RECENT_ACCOUNT} ;'''; - List params = [accountId]; + List params = [accountId.toString()]; final result = await database.rawUpdate(sql, params); DatabaseProvider.databaseLog('Update most recent account used', sql, null, result, params); diff --git a/lib/models/database_provider.dart b/lib/models/database_provider.dart index cb02beec..13c89be7 100644 --- a/lib/models/database_provider.dart +++ b/lib/models/database_provider.dart @@ -211,7 +211,7 @@ class DatabaseProvider { db.rawInsert(CREATE_CONSTANT, [DatabaseConstants.MAX_BUDGET_DATE, maxBudgetDateMillisecondsSinceEpoch]); ///Save account most recently used. - db.rawInsert(CREATE_CONSTANT, [DatabaseConstants.MOST_RECENT_ACCOUNT, 0]); + db.rawInsert(CREATE_CONSTANT, [DatabaseConstants.MOST_RECENT_ACCOUNT, "0"]); } From 56a5b7666583bc08ccc984ea0a3e58ce79637e3f Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 18:35:31 +0100 Subject: [PATCH 14/23] Create v1 to v2 database migration script #32 --- lib/models/database_provider.dart | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/models/database_provider.dart b/lib/models/database_provider.dart index 13c89be7..fa1e4ff5 100644 --- a/lib/models/database_provider.dart +++ b/lib/models/database_provider.dart @@ -57,8 +57,9 @@ class DatabaseProvider { final path = await getDatabasePath('budgetDB'); db = await openDatabase( path, - version: 1, + version: 2, onCreate: _onCreate, + onUpgrade: _onUpgrade, ); return db; @@ -215,8 +216,15 @@ class DatabaseProvider { } - ///Save account most recently used. - db.rawInsert(CREATE_CONSTANT, ["MOST_RECENT_ACCOUNT", 0]); + FutureOr _onUpgrade(Database db, int oldVersion, int newVersion) { + const String CREATE_CONSTANT = '''INSERT INTO ${DatabaseConstants.constantsTable} + (${DatabaseConstants.CONSTANT_NAME}, ${DatabaseConstants.CONSTANT_VALUE}) + VALUES(?, ?);'''; + if(oldVersion == 1){ + ///Save account most recently used. + db.rawInsert(CREATE_CONSTANT, [DatabaseConstants.MOST_RECENT_ACCOUNT, "0"]); + print("Upgrading from version 1 to version 2"); + } } } From 713724db7c0672b3ff709ff511237e16ca81bbfc Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 18:44:20 +0100 Subject: [PATCH 15/23] Specify constant names with single quotes #32 --- lib/models/SQLQueries.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/models/SQLQueries.dart b/lib/models/SQLQueries.dart index b3c3bb59..b53e0479 100644 --- a/lib/models/SQLQueries.dart +++ b/lib/models/SQLQueries.dart @@ -473,7 +473,7 @@ class SQLQueryClass implements Queries{ Future getStartingBudgetDateConstant() async { final sql = '''SELECT ${DatabaseConstants.CONSTANT_VALUE} FROM ${DatabaseConstants.constantsTable} - WHERE ${DatabaseConstants.CONSTANT_NAME} == ${DatabaseConstants.STARTING_BUDGET_DATE};'''; + WHERE ${DatabaseConstants.CONSTANT_NAME} == '${DatabaseConstants.STARTING_BUDGET_DATE}';'''; final data = await database.rawQuery(sql); int startingBudgetDateMillisecondsSinceEpoch = int.parse(data[0]['value'].toString()); @@ -482,7 +482,7 @@ class SQLQueryClass implements Queries{ Future getMaxBudgetDateConstant() async { final sql = '''SELECT ${DatabaseConstants.CONSTANT_VALUE} FROM ${DatabaseConstants.constantsTable} - WHERE ${DatabaseConstants.CONSTANT_NAME} == ${DatabaseConstants.MAX_BUDGET_DATE};'''; + WHERE ${DatabaseConstants.CONSTANT_NAME} == '${DatabaseConstants.MAX_BUDGET_DATE}';'''; final data = await database.rawQuery(sql); int maxBudgetDateMillisecondsSinceEpoch = int.parse(data[0]['value'].toString()); @@ -492,7 +492,7 @@ class SQLQueryClass implements Queries{ Future setMaxBudgetDateConstant(DateTime newMaxBudgetDate) async { final sql = '''UPDATE ${DatabaseConstants.constantsTable} SET ${DatabaseConstants.CONSTANT_VALUE} = ? - WHERE ${DatabaseConstants.CONSTANT_NAME} == ${DatabaseConstants.MAX_BUDGET_DATE} + WHERE ${DatabaseConstants.CONSTANT_NAME} == '${DatabaseConstants.MAX_BUDGET_DATE}' ;'''; List params = [newMaxBudgetDate.millisecondsSinceEpoch]; @@ -506,7 +506,7 @@ class SQLQueryClass implements Queries{ final sql = '''UPDATE ${DatabaseConstants.constantsTable} SET ${DatabaseConstants.CONSTANT_VALUE} = ? - WHERE ${DatabaseConstants.CONSTANT_NAME} == ${DatabaseConstants.MOST_RECENT_ACCOUNT} + WHERE ${DatabaseConstants.CONSTANT_NAME} == '${DatabaseConstants.MOST_RECENT_ACCOUNT}' ;'''; List params = [accountId.toString()]; From 3a9b220eb8164f95f4a445d993a2c6e464b1294c Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 18:49:41 +0100 Subject: [PATCH 16/23] Create setMostRecentAccountUsed() in appState #32 --- lib/appState.dart | 6 ++++++ lib/main.dart | 1 + 2 files changed, 7 insertions(+) diff --git a/lib/appState.dart b/lib/appState.dart index 23e9209c..7eef0478 100644 --- a/lib/appState.dart +++ b/lib/appState.dart @@ -221,6 +221,8 @@ class AppState extends ChangeNotifier { ); _transactions.add(transaction); + setMostRecentAccountUsed(accountId); + if (transaction.subcatID == Constants.TO_BE_BUDGETED_ID_IN_MONEYTRANSACTION) { print("Is to be budgeted money transaction"); // Update balance of the account @@ -677,4 +679,8 @@ class AppState extends ChangeNotifier { DateTime storedMaxBudgetDate = await queryContext.getMaxBudgetDateConstant(); return getMonthDifference(currentMaxBudgetDate, storedMaxBudgetDate); } + + void setMostRecentAccountUsed(int accountId){ + queryContext.updateMostRecentAccountUsed(accountId); + } } diff --git a/lib/main.dart b/lib/main.dart index 14e81a90..31a3bec9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,6 +3,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get_it/get_it.dart'; import 'package:your_budget/appState.dart'; +import 'package:your_budget/models/SQLQueries.dart'; import 'package:your_budget/models/constants.dart'; import 'package:your_budget/screens/addAccount/addAccount.dart'; From 473ccc0e452a143b7368864ff00a950d016d7c44 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 18:53:13 +0100 Subject: [PATCH 17/23] REmove unused imports --- lib/main.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 31a3bec9..efb053c1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,7 +3,6 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get_it/get_it.dart'; import 'package:your_budget/appState.dart'; -import 'package:your_budget/models/SQLQueries.dart'; import 'package:your_budget/models/constants.dart'; import 'package:your_budget/screens/addAccount/addAccount.dart'; @@ -11,7 +10,6 @@ import 'package:your_budget/screens/addTransaction/addTransaction.dart'; import 'package:your_budget/screens/addTransaction/addTransactionState.dart'; import 'package:your_budget/screens/budget/budgetPage.dart'; -import 'package:your_budget/models/database_provider.dart'; import 'package:your_budget/screens/budget/budgetPageState.dart'; import 'package:your_budget/screens/deleteCategories/DeleteCategoriesState.dart'; import 'package:your_budget/screens/showTransactions/showTransactionsState.dart'; From db9a60b3471ae11014a91c2392ac2f65a45c84e3 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 19:13:20 +0100 Subject: [PATCH 18/23] Get most recent account from database #32 --- lib/models/SQLQueries.dart | 11 +++++++++++ lib/models/queries.dart | 2 ++ 2 files changed, 13 insertions(+) diff --git a/lib/models/SQLQueries.dart b/lib/models/SQLQueries.dart index b53e0479..4cbb40f0 100644 --- a/lib/models/SQLQueries.dart +++ b/lib/models/SQLQueries.dart @@ -514,4 +514,15 @@ class SQLQueryClass implements Queries{ DatabaseProvider.databaseLog('Update most recent account used', sql, null, result, params); } + + @override + Future getMostRecentAccountUsed() async { + final sql = '''SELECT ${DatabaseConstants.CONSTANT_VALUE} FROM ${DatabaseConstants.constantsTable} + WHERE ${DatabaseConstants.CONSTANT_NAME} == '${DatabaseConstants.MOST_RECENT_ACCOUNT}';'''; + + final data = await database.rawQuery(sql); + int accountId = int.parse(data[0]['value'].toString()); + print(accountId); + return accountId; + } } diff --git a/lib/models/queries.dart b/lib/models/queries.dart index 414e795f..8cd86f27 100644 --- a/lib/models/queries.dart +++ b/lib/models/queries.dart @@ -144,4 +144,6 @@ abstract class Queries { Future updateMostRecentAccountUsed(int accountId); + Future getMostRecentAccountUsed(); + } From aad0c479c7df885314b90d93942fcd134e5d5d00 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 19:14:26 +0100 Subject: [PATCH 19/23] Use intermediate variable for mostRecentAccount #32 --- lib/appState.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/appState.dart b/lib/appState.dart index 7eef0478..f8d56464 100644 --- a/lib/appState.dart +++ b/lib/appState.dart @@ -25,6 +25,7 @@ class AppState extends ChangeNotifier { List _budgetValues; List _budgets; Queries queryContext; + Account _mostRecentAccount; double toBeBudgeted = 0; @@ -48,6 +49,7 @@ class AppState extends ChangeNotifier { UnmodifiableListView get transactions => UnmodifiableListView(_transactions); UnmodifiableListView get budgets => UnmodifiableListView(_budgets); UnmodifiableListView get goals => UnmodifiableListView(_goals); + Account get mostRecentAccount => _mostRecentAccount ?? _accounts[0]; AppState({@required Queries queryContext}) { this.queryContext = queryContext; @@ -67,9 +69,12 @@ class AppState extends ChangeNotifier { _budgetValues = await queryContext.getBudgetValues(); _goals = await queryContext.getGoals(); + _mostRecentAccount = await getMostRecentAccountUsed(); + currentBudgetDate = getDateFromMonthStart(DateTime.now()); currentBudget = _getBudgetByDate(currentBudgetDate); + await computeToBeBudgeted(); notifyListeners(); @@ -682,5 +687,11 @@ class AppState extends ChangeNotifier { void setMostRecentAccountUsed(int accountId){ queryContext.updateMostRecentAccountUsed(accountId); + _mostRecentAccount = accounts.singleWhere((account) => account.id == accountId, orElse: () => null); + } + + Future getMostRecentAccountUsed() async { + int accountId = await queryContext.getMostRecentAccountUsed(); + return accounts.singleWhere((account) => account.id == accountId, orElse: () => null); } } From 4eefbd1c79fcbf7028973eaacc513d05575b13c3 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 19:15:27 +0100 Subject: [PATCH 20/23] Show transactions of most recent account #32 --- lib/screens/showTransactions/showTransactionsPage.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/screens/showTransactions/showTransactionsPage.dart b/lib/screens/showTransactions/showTransactionsPage.dart index efb9a519..25081334 100644 --- a/lib/screens/showTransactions/showTransactionsPage.dart +++ b/lib/screens/showTransactions/showTransactionsPage.dart @@ -30,7 +30,7 @@ class _ShowTransactionPageController extends State { void initState() { AppState appState = Provider.of(context, listen: false); if (appState.accounts.isNotEmpty) { - account = appState.accounts[0]; + account = appState.mostRecentAccount; } isEditable = false; super.initState(); From 94ceea6b7e25cb7b019896c55d89dc569dd1e43f Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 19:19:06 +0100 Subject: [PATCH 21/23] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7789c02a..f1491a22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Version 1.1.5 + +- FEATURE: Payees are sorted by alphabetical order +- FEATURE: By default, the transactions of the most recently used account are used + ## Version 1.1.4 - BUGFIX: Fix bug where you couldn't delete last character when setting budgeted value for a subcategory From b9eef7c73e8cd721dd739e2b7f1f54a32aa69667 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 19:22:54 +0100 Subject: [PATCH 22/23] Fix wrong version in CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1491a22..7e575fd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,11 @@ # Changelog -## Version 1.1.5 +## Version 1.2.1 - FEATURE: Payees are sorted by alphabetical order - FEATURE: By default, the transactions of the most recently used account are used -## Version 1.1.4 +## Version 1.2.0 - BUGFIX: Fix bug where you couldn't delete last character when setting budgeted value for a subcategory - BUGFIX: Changing the name of a subcategory takes effect immediately From 9aa4f18befd210e2e9fe0c4b2f3e4cebbddddea2 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 9 Jan 2021 19:24:25 +0100 Subject: [PATCH 23/23] Bump version to 1.2.1+15 --- pubspec.yaml | 2 +- version.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 97ba35c0..460c9aed 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.2.0+14 +version: 1.2.1+15 environment: sdk: ">=2.7.0 <3.0.0" diff --git a/version.txt b/version.txt index b25194fd..db008051 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.2.0+14 +1.2.1+15