From 49a61136ab5f09163bfb1cfce9071001faad5575 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 16:24:19 +0100 Subject: [PATCH 01/33] Extract AmountSwitch into separate widget #5 --- .../addTransaction/addTransaction.dart | 24 +++++------------ .../components/amount_switch.dart | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 lib/screens/addTransaction/components/amount_switch.dart diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index afe6cfb9..4056d5c7 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -12,6 +12,7 @@ import 'package:your_budget/models/constants.dart'; import 'package:your_budget/models/entries.dart'; import 'package:your_budget/models/utils.dart'; import 'package:your_budget/screens/addTransaction/components/CurrencyInputFormatter.dart'; +import 'package:your_budget/screens/addTransaction/components/amount_switch.dart'; import 'package:your_budget/screens/addTransaction/selectValue.dart'; import 'package:your_budget/components/widgetViewClasses.dart'; import 'package:your_budget/components/rowContainer.dart'; @@ -349,26 +350,15 @@ class _AddTransactionPageView onTap: () => state.handleAmountOnTap(), )); - Row containerAndButton = Row( - children: [ - Expanded(child: amountInputContainer), - Container( - child: Switch( - value: state.isPositive, - onChanged: (value) => state.handleSwitchOnChanged(), - activeTrackColor: Constants.GREEN_COLOR, - activeColor: Colors.grey[300], - activeThumbImage: new AssetImage("assets/plus.png"), - inactiveThumbImage: new AssetImage("assets/minus.png"), - inactiveTrackColor: Constants.RED_COLOR, - inactiveThumbColor: Colors.grey[300], - )), - ], - ); //Populate the list of container with the number controllers and //the custom listTiles List containerList = [ - containerAndButton, + Row( + children: [ + Expanded(child: amountInputContainer), + AmountSwitch(state: state), + ], + ), GestureDetector( // Payees gesture detectory leading to 'Payees' SelectValuePage onTap: () => state.handleOnTapPayee(), diff --git a/lib/screens/addTransaction/components/amount_switch.dart b/lib/screens/addTransaction/components/amount_switch.dart new file mode 100644 index 00000000..94e4585d --- /dev/null +++ b/lib/screens/addTransaction/components/amount_switch.dart @@ -0,0 +1,27 @@ + +import 'package:flutter/material.dart'; +import 'package:your_budget/models/constants.dart'; + +class AmountSwitch extends StatelessWidget { + const AmountSwitch({ + Key key, + @required this.state, + }) : super(key: key); + + final state; //_AddTransactionPageController + + @override + Widget build(BuildContext context) { + return Container( + child: Switch( + value: state.isPositive, + onChanged: (_) => state.handleSwitchOnChanged(), + activeTrackColor: Constants.GREEN_COLOR, + activeColor: Colors.grey[300], + activeThumbImage: new AssetImage("assets/plus.png"), + inactiveThumbImage: new AssetImage("assets/minus.png"), + inactiveTrackColor: Constants.RED_COLOR, + inactiveThumbColor: Colors.grey[300], + )); + } +} From 941a90fa488cc4cd6c8576028eee1d73d9663582 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 16:36:23 +0100 Subject: [PATCH 02/33] Extract payee field into separate widget #5 --- .../addTransaction/addTransaction.dart | 25 ++++++---------- .../components/payee_field.dart | 30 +++++++++++++++++++ 2 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 lib/screens/addTransaction/components/payee_field.dart diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 4056d5c7..3daa33bf 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -13,6 +13,7 @@ import 'package:your_budget/models/entries.dart'; import 'package:your_budget/models/utils.dart'; import 'package:your_budget/screens/addTransaction/components/CurrencyInputFormatter.dart'; import 'package:your_budget/screens/addTransaction/components/amount_switch.dart'; +import 'package:your_budget/screens/addTransaction/components/payee_field.dart'; import 'package:your_budget/screens/addTransaction/selectValue.dart'; import 'package:your_budget/components/widgetViewClasses.dart'; import 'package:your_budget/components/rowContainer.dart'; @@ -40,7 +41,7 @@ class _AddTransactionPageController extends State { final ScrollController _scrollController = new ScrollController(); /// Default names will have a different style than selected ones - final String _defaultPayeeFieldName = "Select payee"; + final String defaultPayeeFieldName = "Select payee"; final String _defaultAccountFieldName = "Select account"; final String _defaultSubcategoryFieldName = "Select subcategory"; @@ -49,7 +50,7 @@ class _AddTransactionPageController extends State { int amountLength; //Number of max. characters for the amount /// String values of the variables which are displayed. - String _payeeFieldName; + String payeeFieldName; String _accountFieldName; String _subcategoryFieldName; String _dateFieldName; @@ -91,7 +92,7 @@ class _AddTransactionPageController extends State { _date = DateTime.now(); // Set the default values for the UI - _payeeFieldName = _defaultPayeeFieldName; + payeeFieldName = defaultPayeeFieldName; _accountFieldName = _defaultAccountFieldName; _subcategoryFieldName = _defaultSubcategoryFieldName; _dateFieldName = getDateString(_date); @@ -110,7 +111,7 @@ class _AddTransactionPageController extends State { _account = null; _subcategory = null; _date = DateTime.now(); - _payeeFieldName = _defaultPayeeFieldName; + payeeFieldName = defaultPayeeFieldName; _accountFieldName = _defaultAccountFieldName; _subcategoryFieldName = _defaultSubcategoryFieldName; _dateFieldName = getDateString(_date); @@ -128,7 +129,7 @@ class _AddTransactionPageController extends State { /// When tapping on the [SelectValuePage] widget pertaining /// to the [Payee] object, it pushes to the route selecting /// a [Payee], whose value is stored in [_payee] and whose - /// name is stored in [_payeeFieldName]. + /// name is stored in [payeeFieldName]. handleOnTapPayee() { Navigator.push( context, @@ -138,7 +139,7 @@ class _AddTransactionPageController extends State { if (returnElement != null) { setState(() { _payee = returnElement; - _payeeFieldName = returnElement.name; + payeeFieldName = returnElement.name; }); } }); @@ -225,7 +226,7 @@ class _AddTransactionPageController extends State { print("Form validated"); print("Amount : $_amount"); - print("Payee : $_payeeFieldName"); + print("Payee : $payeeFieldName"); print("Account : $_accountFieldName"); print("Subcategory : ${_payee is Payee ? 'No subcategory' : _subcategoryFieldName}"); print("Date: $_dateFieldName"); @@ -359,15 +360,7 @@ class _AddTransactionPageView AmountSwitch(state: state), ], ), - GestureDetector( - // Payees gesture detectory leading to 'Payees' SelectValuePage - onTap: () => state.handleOnTapPayee(), - child: rowContainer( - "Payee", - Text(state._payeeFieldName, - style: (state._payeeFieldName == state._defaultPayeeFieldName) - ? defaultChildTextStyle - : selectedChildTextStyle))), + PayeeField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), GestureDetector( // Accounts gesture detectory leading to 'Accounts' SelectValuePage onTap: () => state.handleOnTapAccount(), diff --git a/lib/screens/addTransaction/components/payee_field.dart b/lib/screens/addTransaction/components/payee_field.dart new file mode 100644 index 00000000..0d3606f2 --- /dev/null +++ b/lib/screens/addTransaction/components/payee_field.dart @@ -0,0 +1,30 @@ + +import 'package:flutter/material.dart'; +import 'package:your_budget/components/rowContainer.dart'; + +class PayeeField extends StatelessWidget { + + final state; //_AddTransactionPageController + final TextStyle defaultChildTextStyle; + final TextStyle selectedChildTextStyle; + + const PayeeField({ + Key key, + @required this.state, + @required this.defaultChildTextStyle, + @required this.selectedChildTextStyle, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return GestureDetector( + // Payees gesture detectory leading to 'Payees' SelectValuePage + onTap: state.handleOnTapPayee, + child: rowContainer( + "Payee", + Text(state.payeeFieldName, + style: (state.payeeFieldName == state.defaultPayeeFieldName) + ? defaultChildTextStyle + : selectedChildTextStyle))); + } +} From 56774b1bf5ed94f3b67516e597e66fff56016dde Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 16:41:46 +0100 Subject: [PATCH 03/33] Extract account field into separate widget #5 --- .../addTransaction/addTransaction.dart | 25 ++++++----------- .../components/account_field.dart | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 lib/screens/addTransaction/components/account_field.dart diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 3daa33bf..a30d1965 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -12,6 +12,7 @@ import 'package:your_budget/models/constants.dart'; import 'package:your_budget/models/entries.dart'; import 'package:your_budget/models/utils.dart'; import 'package:your_budget/screens/addTransaction/components/CurrencyInputFormatter.dart'; +import 'package:your_budget/screens/addTransaction/components/account_field.dart'; import 'package:your_budget/screens/addTransaction/components/amount_switch.dart'; import 'package:your_budget/screens/addTransaction/components/payee_field.dart'; import 'package:your_budget/screens/addTransaction/selectValue.dart'; @@ -42,7 +43,7 @@ class _AddTransactionPageController extends State { /// Default names will have a different style than selected ones final String defaultPayeeFieldName = "Select payee"; - final String _defaultAccountFieldName = "Select account"; + final String defaultAccountFieldName = "Select account"; final String _defaultSubcategoryFieldName = "Select subcategory"; double _amount; @@ -51,7 +52,7 @@ class _AddTransactionPageController extends State { /// String values of the variables which are displayed. String payeeFieldName; - String _accountFieldName; + String accountFieldName; String _subcategoryFieldName; String _dateFieldName; @@ -93,7 +94,7 @@ class _AddTransactionPageController extends State { // Set the default values for the UI payeeFieldName = defaultPayeeFieldName; - _accountFieldName = _defaultAccountFieldName; + accountFieldName = defaultAccountFieldName; _subcategoryFieldName = _defaultSubcategoryFieldName; _dateFieldName = getDateString(_date); @@ -112,7 +113,7 @@ class _AddTransactionPageController extends State { _subcategory = null; _date = DateTime.now(); payeeFieldName = defaultPayeeFieldName; - _accountFieldName = _defaultAccountFieldName; + accountFieldName = defaultAccountFieldName; _subcategoryFieldName = _defaultSubcategoryFieldName; _dateFieldName = getDateString(_date); _amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); @@ -148,7 +149,7 @@ class _AddTransactionPageController extends State { /// When tapping on the [SelectValuePage] widget pertaining /// to the [Account] object, it pushes to the route selecting /// a [Account], whose value is stored in [_account] and whose - /// name is stored in [_accountFieldName]. + /// name is stored in [accountFieldName]. handleOnTapAccount() { Navigator.push( context, @@ -158,7 +159,7 @@ class _AddTransactionPageController extends State { if (returnElement != null) { setState(() { _account = returnElement; - _accountFieldName = returnElement.name; + accountFieldName = returnElement.name; }); } }); @@ -227,7 +228,7 @@ class _AddTransactionPageController extends State { print("Form validated"); print("Amount : $_amount"); print("Payee : $payeeFieldName"); - print("Account : $_accountFieldName"); + print("Account : $accountFieldName"); print("Subcategory : ${_payee is Payee ? 'No subcategory' : _subcategoryFieldName}"); print("Date: $_dateFieldName"); print("Memo : ${_memoController.text}"); @@ -361,15 +362,7 @@ class _AddTransactionPageView ], ), PayeeField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), - GestureDetector( - // Accounts gesture detectory leading to 'Accounts' SelectValuePage - onTap: () => state.handleOnTapAccount(), - child: rowContainer( - "Account", - Text(state._accountFieldName, - style: (state._accountFieldName == state._defaultAccountFieldName) - ? defaultChildTextStyle - : selectedChildTextStyle))), + AccountField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), GestureDetector( // Subcategory gesture detectory leading to 'Categories' SelectValuePage diff --git a/lib/screens/addTransaction/components/account_field.dart b/lib/screens/addTransaction/components/account_field.dart new file mode 100644 index 00000000..399bf433 --- /dev/null +++ b/lib/screens/addTransaction/components/account_field.dart @@ -0,0 +1,28 @@ +import 'package:flutter/material.dart'; +import 'package:your_budget/components/rowContainer.dart'; + +class AccountField extends StatelessWidget { + const AccountField({ + Key key, + @required this.state, + @required this.defaultChildTextStyle, + @required this.selectedChildTextStyle, + }) : super(key: key); + + final state; //_AddTransactionPageController + final TextStyle defaultChildTextStyle; + final TextStyle selectedChildTextStyle; + + @override + Widget build(BuildContext context) { + return GestureDetector( + // Accounts gesture detectory leading to 'Accounts' SelectValuePage + onTap: () => state.handleOnTapAccount(), + child: rowContainer( + "Account", + Text(state.accountFieldName, + style: (state.accountFieldName == state.defaultAccountFieldName) + ? defaultChildTextStyle + : selectedChildTextStyle))); + } +} From 1b46ab12473b64b5582de7f281ab4e2a4b136a0a Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 16:46:25 +0100 Subject: [PATCH 04/33] Extract subcategory field into separate widget #5 --- .../addTransaction/addTransaction.dart | 54 ++++++++----------- .../components/subcategory_field.dart | 35 ++++++++++++ 2 files changed, 56 insertions(+), 33 deletions(-) create mode 100644 lib/screens/addTransaction/components/subcategory_field.dart diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index a30d1965..feaef98b 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -15,6 +15,7 @@ import 'package:your_budget/screens/addTransaction/components/CurrencyInputForma import 'package:your_budget/screens/addTransaction/components/account_field.dart'; import 'package:your_budget/screens/addTransaction/components/amount_switch.dart'; import 'package:your_budget/screens/addTransaction/components/payee_field.dart'; +import 'package:your_budget/screens/addTransaction/components/subcategory_field.dart'; import 'package:your_budget/screens/addTransaction/selectValue.dart'; import 'package:your_budget/components/widgetViewClasses.dart'; import 'package:your_budget/components/rowContainer.dart'; @@ -44,7 +45,7 @@ class _AddTransactionPageController extends State { /// Default names will have a different style than selected ones final String defaultPayeeFieldName = "Select payee"; final String defaultAccountFieldName = "Select account"; - final String _defaultSubcategoryFieldName = "Select subcategory"; + final String defaultSubcategoryFieldName = "Select subcategory"; double _amount; bool isPositive; @@ -53,16 +54,16 @@ class _AddTransactionPageController extends State { /// String values of the variables which are displayed. String payeeFieldName; String accountFieldName; - String _subcategoryFieldName; + String subcategoryFieldName; String _dateFieldName; /// Values used for the transaction - dynamic _payee; + dynamic payee; Account _account; var _subcategory; DateTime _date; - /// List of values to choose each value from, e.g. [_payee] + /// List of values to choose each value from, e.g. [payee] /// will be chosen from one of the [payees] List payees; List subcategories; @@ -87,7 +88,7 @@ class _AddTransactionPageController extends State { payeesAndAccounts.addAll(accounts); // Set initial values of the transaction - _payee = null; + payee = null; _account = null; _subcategory = null; _date = DateTime.now(); @@ -95,7 +96,7 @@ class _AddTransactionPageController extends State { // Set the default values for the UI payeeFieldName = defaultPayeeFieldName; accountFieldName = defaultAccountFieldName; - _subcategoryFieldName = _defaultSubcategoryFieldName; + subcategoryFieldName = defaultSubcategoryFieldName; _dateFieldName = getDateString(_date); _amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); @@ -108,13 +109,13 @@ class _AddTransactionPageController extends State { _amount = 0; amountLength = 16; - _payee = null; + payee = null; _account = null; _subcategory = null; _date = DateTime.now(); payeeFieldName = defaultPayeeFieldName; accountFieldName = defaultAccountFieldName; - _subcategoryFieldName = _defaultSubcategoryFieldName; + subcategoryFieldName = defaultSubcategoryFieldName; _dateFieldName = getDateString(_date); _amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); _memoController.clear(); @@ -129,7 +130,7 @@ class _AddTransactionPageController extends State { /// When tapping on the [SelectValuePage] widget pertaining /// to the [Payee] object, it pushes to the route selecting - /// a [Payee], whose value is stored in [_payee] and whose + /// a [Payee], whose value is stored in [payee] and whose /// name is stored in [payeeFieldName]. handleOnTapPayee() { Navigator.push( @@ -139,7 +140,7 @@ class _AddTransactionPageController extends State { ).then((returnElement) { if (returnElement != null) { setState(() { - _payee = returnElement; + payee = returnElement; payeeFieldName = returnElement.name; }); } @@ -168,7 +169,7 @@ class _AddTransactionPageController extends State { /// When tapping on the [SelectValuePage] widget pertaining /// to the [SubCategory] object, it pushes to the route selecting /// a [SubCategory], whose value is stored in [_subcategory] and whose - /// name is stored in [_subcategoryFieldName]. + /// name is stored in [subcategoryFieldName]. handleOnTapCategory() async { dynamic returnElement = await Navigator.push( context, @@ -188,7 +189,7 @@ class _AddTransactionPageController extends State { if (returnElement != null) { setState(() { _subcategory = returnElement; - _subcategoryFieldName = + subcategoryFieldName = returnElement is SubCategory ? returnElement.name : returnElement.data; }); } @@ -222,21 +223,21 @@ class _AddTransactionPageController extends State { void addMoneyTransaction() async { _formKey.currentState.save(); if (_formKey.currentState.validate()) { - if (_payee != null && _account != null) { + if (payee != null && _account != null) { _amount = formatCurrencyToDouble(_amountController.text, isPositive); print("Form validated"); print("Amount : $_amount"); print("Payee : $payeeFieldName"); print("Account : $accountFieldName"); - print("Subcategory : ${_payee is Payee ? 'No subcategory' : _subcategoryFieldName}"); + print("Subcategory : ${payee is Payee ? 'No subcategory' : subcategoryFieldName}"); print("Date: $_dateFieldName"); print("Memo : ${_memoController.text}"); // Input as payee ID the opposite of the account ID when we select // an account instead of a payee in the 'Payee' field - print("_payee is of type ${_payee is Payee ? "Payee" : "Account"}"); - int payeeId = _payee is Payee ? _payee.id : -_account.id; + print("payee is of type ${payee is Payee ? "Payee" : "Account"}"); + int payeeId = payee is Payee ? payee.id : -_account.id; appState.addTransaction( subcatId: _selectSubcatId(), @@ -256,10 +257,10 @@ class _AddTransactionPageController extends State { } _selectSubcatId() { - bool subcategoryIsToBeBudgeted = _subcategoryFieldName == "To be budgeted"; - if (_payee is Payee && !subcategoryIsToBeBudgeted) + bool subcategoryIsToBeBudgeted = subcategoryFieldName == "To be budgeted"; + if (payee is Payee && !subcategoryIsToBeBudgeted) return _subcategory.id; - else if (_payee is Account && !subcategoryIsToBeBudgeted) + else if (payee is Account && !subcategoryIsToBeBudgeted) return Constants.UNASSIGNED_SUBCAT_ID; else if (subcategoryIsToBeBudgeted) // return Constants.TO_BE_BUDGETED_ID_IN_MONEYTRANSACTION; @@ -363,20 +364,7 @@ class _AddTransactionPageView ), PayeeField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), AccountField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), - GestureDetector( - // Subcategory gesture detectory leading to 'Categories' SelectValuePage - - /// [state._payee] accepts both an object of type [Payee] or [Account]. - /// If it is of type Account, make the GestureDetector untappable, - /// set the default text style and change the text. - onTap: () => state._payee is Account ? null : state.handleOnTapCategory(), - child: rowContainer( - "Category", - Text(state._payee is Account ? "No subcategory needed" : state._subcategoryFieldName, - style: (state._subcategoryFieldName == state._defaultSubcategoryFieldName || - state._payee is Account) - ? defaultChildTextStyle - : selectedChildTextStyle))), + SubcategoryField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), GestureDetector( // Date gesture detector onTap: () => state.handleOnTapDate(state.context), diff --git a/lib/screens/addTransaction/components/subcategory_field.dart b/lib/screens/addTransaction/components/subcategory_field.dart new file mode 100644 index 00000000..f1dc71ad --- /dev/null +++ b/lib/screens/addTransaction/components/subcategory_field.dart @@ -0,0 +1,35 @@ + +import 'package:flutter/material.dart'; +import 'package:your_budget/components/rowContainer.dart'; +import 'package:your_budget/models/entries.dart'; + +class SubcategoryField extends StatelessWidget { + const SubcategoryField({ + Key key, + @required this.state, + @required this.defaultChildTextStyle, + @required this.selectedChildTextStyle, + }) : super(key: key); + + final state; //_AddTransactionPageController + final TextStyle defaultChildTextStyle; + final TextStyle selectedChildTextStyle; + + @override + Widget build(BuildContext context) { + return GestureDetector( + // Subcategory gesture detectory leading to 'Categories' SelectValuePage + + /// [state.payee] accepts both an object of type [Payee] or [Account]. + /// If it is of type Account, make the GestureDetector untappable, + /// set the default text style and change the text. + onTap: () => state.payee is Account ? null : state.handleOnTapCategory(), + child: rowContainer( + "Category", + Text(state.payee is Account ? "No subcategory needed" : state.subcategoryFieldName, + style: (state.subcategoryFieldName == state.defaultSubcategoryFieldName || + state.payee is Account) + ? defaultChildTextStyle + : selectedChildTextStyle))); + } +} From be1f74d19faf584ebe282f19fe531e3d04cf12c6 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 16:49:49 +0100 Subject: [PATCH 05/33] Extract date field into separate widget #5 --- .../addTransaction/addTransaction.dart | 18 ++++++------- .../addTransaction/components/date_field.dart | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 lib/screens/addTransaction/components/date_field.dart diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index feaef98b..cfce3444 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -14,6 +14,7 @@ import 'package:your_budget/models/utils.dart'; import 'package:your_budget/screens/addTransaction/components/CurrencyInputFormatter.dart'; import 'package:your_budget/screens/addTransaction/components/account_field.dart'; import 'package:your_budget/screens/addTransaction/components/amount_switch.dart'; +import 'package:your_budget/screens/addTransaction/components/date_field.dart'; import 'package:your_budget/screens/addTransaction/components/payee_field.dart'; import 'package:your_budget/screens/addTransaction/components/subcategory_field.dart'; import 'package:your_budget/screens/addTransaction/selectValue.dart'; @@ -55,7 +56,7 @@ class _AddTransactionPageController extends State { String payeeFieldName; String accountFieldName; String subcategoryFieldName; - String _dateFieldName; + String dateFieldName; /// Values used for the transaction dynamic payee; @@ -97,7 +98,7 @@ class _AddTransactionPageController extends State { payeeFieldName = defaultPayeeFieldName; accountFieldName = defaultAccountFieldName; subcategoryFieldName = defaultSubcategoryFieldName; - _dateFieldName = getDateString(_date); + dateFieldName = getDateString(_date); _amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); } @@ -116,7 +117,7 @@ class _AddTransactionPageController extends State { payeeFieldName = defaultPayeeFieldName; accountFieldName = defaultAccountFieldName; subcategoryFieldName = defaultSubcategoryFieldName; - _dateFieldName = getDateString(_date); + dateFieldName = getDateString(_date); _amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); _memoController.clear(); }); @@ -199,7 +200,7 @@ class _AddTransactionPageController extends State { /// which allows one to choose the date as a [DateTime]. /// Defaults to the current day-year-month. /// The [DateTime] gets stored in [_date], and the string - /// value of that date is saved in [_dateFieldName]. + /// value of that date is saved in [dateFieldName]. Future handleOnTapDate(BuildContext context) async { DateTime picked = await showDatePicker( context: context, @@ -210,7 +211,7 @@ class _AddTransactionPageController extends State { picked = addExactEntryTime(picked); setState(() { _date = picked; - _dateFieldName = getDateString(picked); + dateFieldName = getDateString(picked); }); } @@ -231,7 +232,7 @@ class _AddTransactionPageController extends State { print("Payee : $payeeFieldName"); print("Account : $accountFieldName"); print("Subcategory : ${payee is Payee ? 'No subcategory' : subcategoryFieldName}"); - print("Date: $_dateFieldName"); + print("Date: $dateFieldName"); print("Memo : ${_memoController.text}"); // Input as payee ID the opposite of the account ID when we select @@ -365,10 +366,7 @@ class _AddTransactionPageView PayeeField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), AccountField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), SubcategoryField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), - GestureDetector( - // Date gesture detector - onTap: () => state.handleOnTapDate(state.context), - child: rowContainer("Date", Text(state._dateFieldName, style: selectedChildTextStyle))), + DateField(state: state, selectedChildTextStyle: selectedChildTextStyle), rowContainer( "Memo", TextField( diff --git a/lib/screens/addTransaction/components/date_field.dart b/lib/screens/addTransaction/components/date_field.dart new file mode 100644 index 00000000..131697f3 --- /dev/null +++ b/lib/screens/addTransaction/components/date_field.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:your_budget/components/rowContainer.dart'; + +class DateField extends StatelessWidget { + const DateField({ + Key key, + @required this.state, + @required this.selectedChildTextStyle, + }) : super(key: key); + + final state; //_AddTransactionPageController + final TextStyle selectedChildTextStyle; + + @override + Widget build(BuildContext context) { + return GestureDetector( + // Date gesture detector + onTap: () => state.handleOnTapDate(state.context), + child: rowContainer( + "Date", + Text( + state.dateFieldName, + style: selectedChildTextStyle, + ))); + } +} From e74280d118c86e26eb1bc698f00c235d715a23c5 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 16:54:39 +0100 Subject: [PATCH 06/33] Extract memo field into separate widget #5 --- .../addTransaction/addTransaction.dart | 17 ++++++----------- .../addTransaction/components/memo_field.dart | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 lib/screens/addTransaction/components/memo_field.dart diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index cfce3444..0d40bdd1 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -16,6 +16,7 @@ import 'package:your_budget/screens/addTransaction/components/account_field.dart import 'package:your_budget/screens/addTransaction/components/amount_switch.dart'; import 'package:your_budget/screens/addTransaction/components/date_field.dart'; import 'package:your_budget/screens/addTransaction/components/payee_field.dart'; +import 'package:your_budget/screens/addTransaction/components/memo_field.dart'; import 'package:your_budget/screens/addTransaction/components/subcategory_field.dart'; import 'package:your_budget/screens/addTransaction/selectValue.dart'; import 'package:your_budget/components/widgetViewClasses.dart'; @@ -40,7 +41,7 @@ class _AddTransactionPageController extends State { final _formKey = GlobalKey(); - final TextEditingController _memoController = new TextEditingController(); + final TextEditingController memoController = new TextEditingController(); final ScrollController _scrollController = new ScrollController(); /// Default names will have a different style than selected ones @@ -119,7 +120,7 @@ class _AddTransactionPageController extends State { subcategoryFieldName = defaultSubcategoryFieldName; dateFieldName = getDateString(_date); _amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); - _memoController.clear(); + memoController.clear(); }); } @@ -233,7 +234,7 @@ class _AddTransactionPageController extends State { print("Account : $accountFieldName"); print("Subcategory : ${payee is Payee ? 'No subcategory' : subcategoryFieldName}"); print("Date: $dateFieldName"); - print("Memo : ${_memoController.text}"); + print("Memo : ${memoController.text}"); // Input as payee ID the opposite of the account ID when we select // an account instead of a payee in the 'Payee' field @@ -245,7 +246,7 @@ class _AddTransactionPageController extends State { payeeId: payeeId, accountId: _account.id, amount: _amount, - memo: _memoController.text, + memo: memoController.text, date: _date, ); @@ -367,13 +368,7 @@ class _AddTransactionPageView AccountField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), SubcategoryField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), DateField(state: state, selectedChildTextStyle: selectedChildTextStyle), - rowContainer( - "Memo", - TextField( - decoration: new InputDecoration(hintText: "Add a memo"), - controller: state._memoController, - ), - ), + MemoField(state: state), ]; // Build the layout (ListView, error container, Button) diff --git a/lib/screens/addTransaction/components/memo_field.dart b/lib/screens/addTransaction/components/memo_field.dart new file mode 100644 index 00000000..84c83f86 --- /dev/null +++ b/lib/screens/addTransaction/components/memo_field.dart @@ -0,0 +1,19 @@ +import 'package:flutter/material.dart'; +import 'package:your_budget/components/rowContainer.dart'; + +class MemoField extends StatelessWidget { + final state; //_AddTransactionPageController + + const MemoField({Key key, @required this.state}) : super(key: key); + + @override + Widget build(BuildContext context) { + return rowContainer( + "Memo", + TextField( + decoration: new InputDecoration(hintText: "Add a memo"), + controller: state.memoController, + ), + ); + } +} From 312ed54d61683fa82b89d8cb1a5a31714248dd1d Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 16:57:41 +0100 Subject: [PATCH 07/33] Use Column widget instead of ListView #5 --- .../addTransaction/addTransaction.dart | 40 ++++++------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 0d40bdd1..80243edc 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -355,23 +355,6 @@ class _AddTransactionPageView onTap: () => state.handleAmountOnTap(), )); - //Populate the list of container with the number controllers and - //the custom listTiles - List containerList = [ - Row( - children: [ - Expanded(child: amountInputContainer), - AmountSwitch(state: state), - ], - ), - PayeeField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), - AccountField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), - SubcategoryField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), - DateField(state: state, selectedChildTextStyle: selectedChildTextStyle), - MemoField(state: state), - ]; - - // Build the layout (ListView, error container, Button) return SingleChildScrollView( child: Column(children: [ Container( @@ -379,17 +362,18 @@ class _AddTransactionPageView child: Scrollbar( isAlwaysShown: true, controller: state._scrollController, - child: ListView.separated( - controller: state._scrollController, - shrinkWrap: false, - addAutomaticKeepAlives: true, - itemCount: containerList.length, - separatorBuilder: (BuildContext context, int index) => - Divider(height: 1, color: Colors.black26), - itemBuilder: (context, index) { - return containerList[index]; - }), - )), + child: Column(children: [ Row( + children: [ + Expanded(child: amountInputContainer), + AmountSwitch(state: state), + ], + ), + PayeeField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), + AccountField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), + SubcategoryField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), + DateField(state: state, selectedChildTextStyle: selectedChildTextStyle), + MemoField(state: state),],), + )), // TODO: Error message FloatingActionButton( child: Text("Enter"), From cfad37d153f56e3f888f4ad6ee5349b0c8cf6fa5 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 17:04:33 +0100 Subject: [PATCH 08/33] Extract amount input into separate widget #5 --- .../addTransaction/addTransaction.dart | 66 +++++-------------- .../components/amount_input_container.dart | 57 ++++++++++++++++ 2 files changed, 73 insertions(+), 50 deletions(-) create mode 100644 lib/screens/addTransaction/components/amount_input_container.dart diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 80243edc..dcdc33c9 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -17,6 +17,7 @@ import 'package:your_budget/screens/addTransaction/components/amount_switch.dart import 'package:your_budget/screens/addTransaction/components/date_field.dart'; import 'package:your_budget/screens/addTransaction/components/payee_field.dart'; import 'package:your_budget/screens/addTransaction/components/memo_field.dart'; +import 'package:your_budget/screens/addTransaction/components/amount_input_container.dart'; import 'package:your_budget/screens/addTransaction/components/subcategory_field.dart'; import 'package:your_budget/screens/addTransaction/selectValue.dart'; import 'package:your_budget/components/widgetViewClasses.dart'; @@ -30,15 +31,10 @@ class AddTransactionPage extends StatefulWidget { } class _AddTransactionPageController extends State { - TextEditingController _amountController; + TextEditingController amountController; final NumberFormat currencyNumberFormat = NumberFormat.currency(locale: 'de', decimalDigits: 2, symbol: '€'); - final TextStyle _positiveAmountTextStyle = - new TextStyle(color: Constants.GREEN_COLOR, fontSize: 32.0); - final TextStyle _negativeAmountTextStyle = - new TextStyle(color: Constants.RED_COLOR, fontSize: 32.0); - final _formKey = GlobalKey(); final TextEditingController memoController = new TextEditingController(); @@ -101,7 +97,7 @@ class _AddTransactionPageController extends State { subcategoryFieldName = defaultSubcategoryFieldName; dateFieldName = getDateString(_date); - _amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); + amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); } /// Resets all the field to their default value @@ -119,14 +115,14 @@ class _AddTransactionPageController extends State { accountFieldName = defaultAccountFieldName; subcategoryFieldName = defaultSubcategoryFieldName; dateFieldName = getDateString(_date); - _amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); + amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); memoController.clear(); }); } @override void dispose() { - _amountController.dispose(); + amountController.dispose(); super.dispose(); } @@ -226,7 +222,7 @@ class _AddTransactionPageController extends State { _formKey.currentState.save(); if (_formKey.currentState.validate()) { if (payee != null && _account != null) { - _amount = formatCurrencyToDouble(_amountController.text, isPositive); + _amount = formatCurrencyToDouble(amountController.text, isPositive); print("Form validated"); print("Amount : $_amount"); @@ -269,7 +265,7 @@ class _AddTransactionPageController extends State { } handleAmountOnSave() { - _amount = formatCurrencyToDouble(_amountController.text, isPositive); + _amount = formatCurrencyToDouble(amountController.text, isPositive); } // When the switch is set to the 'off' position, the text style changes @@ -277,9 +273,9 @@ class _AddTransactionPageController extends State { void handleSwitchOnChanged() { setState(() { isPositive = !isPositive; - if (isPositive && _amountController.text[0] == '-') - _amountController.text = _amountController.text.substring(1); - else if (!isPositive) _amountController.text = "-" + _amountController.text; + if (isPositive && amountController.text[0] == '-') + amountController.text = amountController.text.substring(1); + else if (!isPositive) amountController.text = "-" + amountController.text; // Change the maximal possible length of the amount to account for // the minus sign. @@ -291,24 +287,24 @@ class _AddTransactionPageController extends State { /// Checks that the amount of the transaction is not 0. handleAmountValidate(String value) { - if (formatCurrencyToDouble(_amountController.text, isPositive) == 0) { + if (formatCurrencyToDouble(amountController.text, isPositive) == 0) { return "Value must be different than 0"; } return null; } - /// Reset [_amountController.text] to "0.00 €" or "-0.00€", depending on + /// Reset [amountController.text] to "0.00 €" or "-0.00€", depending on /// the value of [isPositive] handleAmountOnTap() { String zero = currencyNumberFormat.format(0).trim(); - _amountController.text = isPositive ? zero : "-" + zero; + amountController.text = isPositive ? zero : "-" + zero; _setOffsetToLastDigit(); } /// Set the cursor offset to the last digit of the text. _setOffsetToLastDigit() { - _amountController.selection = - TextSelection.collapsed(offset: _amountController.text.length - 2); + amountController.selection = + TextSelection.collapsed(offset: amountController.text.length - 2); } @override @@ -324,36 +320,6 @@ class _AddTransactionPageView final TextStyle selectedChildTextStyle = TextStyle(color: Colors.black, fontSize: 16.0); Widget _myBuildMethod() { - // Create number controller - /// This [TextFormField] handles the amount selected while providing - /// an intuitive experience to the user, who does not need to manually - /// separators and currencies. - /// The length is limited by a [LengthLimitingTextInputFormatter] to - /// [state.amountLength] which is equivalent to a maximal value of - /// 999.999.999,99 €. - /// The currency format is handled by [CurrencyInputFormatter]. - /// [onTap()] resets the value to a chosen default value. - Container amountInputContainer = Container( - height: 50, - alignment: Alignment.centerRight, - padding: new EdgeInsets.symmetric(horizontal: 10.0), - child: TextFormField( - decoration: new InputDecoration.collapsed( - hintText: "", - ), - keyboardType: TextInputType.number, - controller: state._amountController, - inputFormatters: [ - LengthLimitingTextInputFormatter(state.amountLength), - CurrencyInputFormatter(state.currencyNumberFormat, state.isPositive), - ], - textInputAction: TextInputAction.done, - textAlign: TextAlign.right, - style: state.isPositive ? state._positiveAmountTextStyle : state._negativeAmountTextStyle, - validator: (value) => state.handleAmountValidate(value), - // onSaved: state.handleAmountOnSave(), - onTap: () => state.handleAmountOnTap(), - )); return SingleChildScrollView( child: Column(children: [ @@ -364,7 +330,7 @@ class _AddTransactionPageView controller: state._scrollController, child: Column(children: [ Row( children: [ - Expanded(child: amountInputContainer), + Expanded(child: AmountInputContainer(state: state)), AmountSwitch(state: state), ], ), diff --git a/lib/screens/addTransaction/components/amount_input_container.dart b/lib/screens/addTransaction/components/amount_input_container.dart new file mode 100644 index 00000000..52c1f2ec --- /dev/null +++ b/lib/screens/addTransaction/components/amount_input_container.dart @@ -0,0 +1,57 @@ + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:your_budget/models/constants.dart'; +import 'package:your_budget/screens/addTransaction/components/CurrencyInputFormatter.dart'; + +class AmountInputContainer extends StatelessWidget { + // Create number controller + /// This [TextFormField] handles the amount selected while providing + /// an intuitive experience to the user, who does not need to manually + /// separators and currencies. + /// The length is limited by a [LengthLimitingTextInputFormatter] to + /// [state.amountLength] which is equivalent to a maximal value of + /// 999.999.999,99 €. + /// The currency format is handled by [CurrencyInputFormatter]. + /// [onTap()] resets the value to a chosen default value. + + AmountInputContainer({ + Key key, + @required this.state, + }) : super(key: key); + + final state; //_AddTransactionPageController + + + + final TextStyle _positiveAmountTextStyle = + TextStyle(color: Constants.GREEN_COLOR, fontSize: 32.0); + final TextStyle _negativeAmountTextStyle = + TextStyle(color: Constants.RED_COLOR, fontSize: 32.0); + + + @override + Widget build(BuildContext context) { + return Container( + height: 50, + alignment: Alignment.centerRight, + padding: new EdgeInsets.symmetric(horizontal: 10.0), + child: TextFormField( + decoration: new InputDecoration.collapsed( + hintText: "", + ), + keyboardType: TextInputType.number, + controller: state.amountController, + inputFormatters: [ + LengthLimitingTextInputFormatter(state.amountLength), + CurrencyInputFormatter(state.currencyNumberFormat, state.isPositive), + ], + textInputAction: TextInputAction.done, + textAlign: TextAlign.right, + style: state.isPositive ? _positiveAmountTextStyle : _negativeAmountTextStyle, + validator: (value) => state.handleAmountValidate(value), + // onSaved: state.han dleAmountOnSave(), + onTap: () => state.handleAmountOnTap(), + )); + } +} From ca04bfafe556c192c869e620bca018598f4f7615 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 17:11:20 +0100 Subject: [PATCH 09/33] Fix imports and format #5 --- .../addTransaction/addTransaction.dart | 114 ++++++++++-------- .../components/account_field.dart | 3 +- .../components/amount_input_container.dart | 34 +++--- .../components/amount_switch.dart | 6 +- .../addTransaction/components/date_field.dart | 3 +- .../addTransaction/components/memo_field.dart | 3 +- .../components/payee_field.dart | 7 +- .../components/subcategory_field.dart | 5 +- 8 files changed, 99 insertions(+), 76 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index dcdc33c9..199987f6 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -4,30 +4,29 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; - -import 'package:your_budget/appState.dart'; -import 'package:your_budget/components/overlayNotifications.dart'; -import 'package:your_budget/models/categories.dart'; -import 'package:your_budget/models/constants.dart'; -import 'package:your_budget/models/entries.dart'; -import 'package:your_budget/models/utils.dart'; -import 'package:your_budget/screens/addTransaction/components/CurrencyInputFormatter.dart'; -import 'package:your_budget/screens/addTransaction/components/account_field.dart'; -import 'package:your_budget/screens/addTransaction/components/amount_switch.dart'; -import 'package:your_budget/screens/addTransaction/components/date_field.dart'; -import 'package:your_budget/screens/addTransaction/components/payee_field.dart'; -import 'package:your_budget/screens/addTransaction/components/memo_field.dart'; -import 'package:your_budget/screens/addTransaction/components/amount_input_container.dart'; -import 'package:your_budget/screens/addTransaction/components/subcategory_field.dart'; -import 'package:your_budget/screens/addTransaction/selectValue.dart'; -import 'package:your_budget/components/widgetViewClasses.dart'; -import 'package:your_budget/components/rowContainer.dart'; - import 'package:provider/provider.dart'; +import '../../appState.dart'; +import '../../components/overlayNotifications.dart'; +import '../../components/widgetViewClasses.dart'; +import '../../models/categories.dart'; +import '../../models/constants.dart'; +import '../../models/entries.dart'; +import '../../models/utils.dart'; +import 'components/CurrencyInputFormatter.dart'; +import 'components/account_field.dart'; +import 'components/amount_input_container.dart'; +import 'components/amount_switch.dart'; +import 'components/date_field.dart'; +import 'components/memo_field.dart'; +import 'components/payee_field.dart'; +import 'components/subcategory_field.dart'; +import 'selectValue.dart'; + class AddTransactionPage extends StatefulWidget { @override - _AddTransactionPageController createState() => _AddTransactionPageController(); + _AddTransactionPageController createState() => + _AddTransactionPageController(); } class _AddTransactionPageController extends State { @@ -97,7 +96,8 @@ class _AddTransactionPageController extends State { subcategoryFieldName = defaultSubcategoryFieldName; dateFieldName = getDateString(_date); - amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); + amountController = + TextEditingController(text: currencyNumberFormat.format(0).trim()); } /// Resets all the field to their default value @@ -115,7 +115,8 @@ class _AddTransactionPageController extends State { accountFieldName = defaultAccountFieldName; subcategoryFieldName = defaultSubcategoryFieldName; dateFieldName = getDateString(_date); - amountController = TextEditingController(text: currencyNumberFormat.format(0).trim()); + amountController = + TextEditingController(text: currencyNumberFormat.format(0).trim()); memoController.clear(); }); } @@ -134,7 +135,8 @@ class _AddTransactionPageController extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => SelectValuePage(title: "Payees", listEntries: payeesAndAccounts)), + builder: (context) => + SelectValuePage(title: "Payees", listEntries: payeesAndAccounts)), ).then((returnElement) { if (returnElement != null) { setState(() { @@ -153,7 +155,8 @@ class _AddTransactionPageController extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => SelectValuePage(title: "Accounts", listEntries: accounts)), + builder: (context) => + SelectValuePage(title: "Accounts", listEntries: accounts)), ).then((returnElement) { if (returnElement != null) { setState(() { @@ -179,7 +182,8 @@ class _AddTransactionPageController extends State { }); subcatAndToBeBudgeted.add(Text("To be budgeted")); - return SelectValuePage(title: "Subcategories", listEntries: subcatAndToBeBudgeted); + return SelectValuePage( + title: "Subcategories", listEntries: subcatAndToBeBudgeted); }, ), ); @@ -187,8 +191,9 @@ class _AddTransactionPageController extends State { if (returnElement != null) { setState(() { _subcategory = returnElement; - subcategoryFieldName = - returnElement is SubCategory ? returnElement.name : returnElement.data; + subcategoryFieldName = returnElement is SubCategory + ? returnElement.name + : returnElement.data; }); } } @@ -204,12 +209,11 @@ class _AddTransactionPageController extends State { initialDate: getDateYMD(_date), firstDate: appState.startingBudgetDate, lastDate: getLastDayOfMonth(getMaxBudgetDate())); - if (picked != null && picked != _date) - picked = addExactEntryTime(picked); - setState(() { - _date = picked; - dateFieldName = getDateString(picked); - }); + if (picked != null && picked != _date) picked = addExactEntryTime(picked); + setState(() { + _date = picked; + dateFieldName = getDateString(picked); + }); } /// Check that all the necessary fields in the form @@ -228,7 +232,8 @@ class _AddTransactionPageController extends State { print("Amount : $_amount"); print("Payee : $payeeFieldName"); print("Account : $accountFieldName"); - print("Subcategory : ${payee is Payee ? 'No subcategory' : subcategoryFieldName}"); + print( + "Subcategory : ${payee is Payee ? 'No subcategory' : subcategoryFieldName}"); print("Date: $dateFieldName"); print("Memo : ${memoController.text}"); @@ -315,12 +320,12 @@ class _AddTransactionPageView extends WidgetView { _AddTransactionPageView(_AddTransactionPageController state) : super(state); - final TextStyle defaultChildTextStyle = - TextStyle(color: Colors.grey, fontStyle: FontStyle.italic, fontSize: 16.0); - final TextStyle selectedChildTextStyle = TextStyle(color: Colors.black, fontSize: 16.0); + final TextStyle defaultChildTextStyle = TextStyle( + color: Colors.grey, fontStyle: FontStyle.italic, fontSize: 16.0); + final TextStyle selectedChildTextStyle = + TextStyle(color: Colors.black, fontSize: 16.0); Widget _myBuildMethod() { - return SingleChildScrollView( child: Column(children: [ Container( @@ -328,18 +333,33 @@ class _AddTransactionPageView child: Scrollbar( isAlwaysShown: true, controller: state._scrollController, - child: Column(children: [ Row( + child: Column( children: [ - Expanded(child: AmountInputContainer(state: state)), - AmountSwitch(state: state), + Row( + children: [ + Expanded(child: AmountInputContainer(state: state)), + AmountSwitch(state: state), + ], + ), + PayeeField( + state: state, + defaultChildTextStyle: defaultChildTextStyle, + selectedChildTextStyle: selectedChildTextStyle), + AccountField( + state: state, + defaultChildTextStyle: defaultChildTextStyle, + selectedChildTextStyle: selectedChildTextStyle), + SubcategoryField( + state: state, + defaultChildTextStyle: defaultChildTextStyle, + selectedChildTextStyle: selectedChildTextStyle), + DateField( + state: state, + selectedChildTextStyle: selectedChildTextStyle), + MemoField(state: state), ], ), - PayeeField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), - AccountField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), - SubcategoryField(state: state, defaultChildTextStyle: defaultChildTextStyle, selectedChildTextStyle: selectedChildTextStyle), - DateField(state: state, selectedChildTextStyle: selectedChildTextStyle), - MemoField(state: state),],), - )), + )), // TODO: Error message FloatingActionButton( child: Text("Enter"), diff --git a/lib/screens/addTransaction/components/account_field.dart b/lib/screens/addTransaction/components/account_field.dart index 399bf433..6d0fb10f 100644 --- a/lib/screens/addTransaction/components/account_field.dart +++ b/lib/screens/addTransaction/components/account_field.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:your_budget/components/rowContainer.dart'; + +import '../../../components/rowContainer.dart'; class AccountField extends StatelessWidget { const AccountField({ diff --git a/lib/screens/addTransaction/components/amount_input_container.dart b/lib/screens/addTransaction/components/amount_input_container.dart index 52c1f2ec..b70ca0e3 100644 --- a/lib/screens/addTransaction/components/amount_input_container.dart +++ b/lib/screens/addTransaction/components/amount_input_container.dart @@ -1,19 +1,19 @@ - import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:your_budget/models/constants.dart'; -import 'package:your_budget/screens/addTransaction/components/CurrencyInputFormatter.dart'; + +import '../../../models/constants.dart'; +import 'CurrencyInputFormatter.dart'; class AmountInputContainer extends StatelessWidget { - // Create number controller - /// This [TextFormField] handles the amount selected while providing - /// an intuitive experience to the user, who does not need to manually - /// separators and currencies. - /// The length is limited by a [LengthLimitingTextInputFormatter] to - /// [state.amountLength] which is equivalent to a maximal value of - /// 999.999.999,99 €. - /// The currency format is handled by [CurrencyInputFormatter]. - /// [onTap()] resets the value to a chosen default value. + // Create number controller + /// This [TextFormField] handles the amount selected while providing + /// an intuitive experience to the user, who does not need to manually + /// separators and currencies. + /// The length is limited by a [LengthLimitingTextInputFormatter] to + /// [state.amountLength] which is equivalent to a maximal value of + /// 999.999.999,99 €. + /// The currency format is handled by [CurrencyInputFormatter]. + /// [onTap()] resets the value to a chosen default value. AmountInputContainer({ Key key, @@ -22,14 +22,11 @@ class AmountInputContainer extends StatelessWidget { final state; //_AddTransactionPageController - - final TextStyle _positiveAmountTextStyle = TextStyle(color: Constants.GREEN_COLOR, fontSize: 32.0); final TextStyle _negativeAmountTextStyle = TextStyle(color: Constants.RED_COLOR, fontSize: 32.0); - @override Widget build(BuildContext context) { return Container( @@ -44,11 +41,14 @@ class AmountInputContainer extends StatelessWidget { controller: state.amountController, inputFormatters: [ LengthLimitingTextInputFormatter(state.amountLength), - CurrencyInputFormatter(state.currencyNumberFormat, state.isPositive), + CurrencyInputFormatter( + state.currencyNumberFormat, state.isPositive), ], textInputAction: TextInputAction.done, textAlign: TextAlign.right, - style: state.isPositive ? _positiveAmountTextStyle : _negativeAmountTextStyle, + style: state.isPositive + ? _positiveAmountTextStyle + : _negativeAmountTextStyle, validator: (value) => state.handleAmountValidate(value), // onSaved: state.han dleAmountOnSave(), onTap: () => state.handleAmountOnTap(), diff --git a/lib/screens/addTransaction/components/amount_switch.dart b/lib/screens/addTransaction/components/amount_switch.dart index 94e4585d..637f3dd2 100644 --- a/lib/screens/addTransaction/components/amount_switch.dart +++ b/lib/screens/addTransaction/components/amount_switch.dart @@ -1,6 +1,6 @@ - import 'package:flutter/material.dart'; -import 'package:your_budget/models/constants.dart'; + +import '../../../models/constants.dart'; class AmountSwitch extends StatelessWidget { const AmountSwitch({ @@ -8,7 +8,7 @@ class AmountSwitch extends StatelessWidget { @required this.state, }) : super(key: key); - final state; //_AddTransactionPageController + final state; //_AddTransactionPageController @override Widget build(BuildContext context) { diff --git a/lib/screens/addTransaction/components/date_field.dart b/lib/screens/addTransaction/components/date_field.dart index 131697f3..b857d7a7 100644 --- a/lib/screens/addTransaction/components/date_field.dart +++ b/lib/screens/addTransaction/components/date_field.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:your_budget/components/rowContainer.dart'; + +import '../../../components/rowContainer.dart'; class DateField extends StatelessWidget { const DateField({ diff --git a/lib/screens/addTransaction/components/memo_field.dart b/lib/screens/addTransaction/components/memo_field.dart index 84c83f86..fcbf4afc 100644 --- a/lib/screens/addTransaction/components/memo_field.dart +++ b/lib/screens/addTransaction/components/memo_field.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:your_budget/components/rowContainer.dart'; + +import '../../../components/rowContainer.dart'; class MemoField extends StatelessWidget { final state; //_AddTransactionPageController diff --git a/lib/screens/addTransaction/components/payee_field.dart b/lib/screens/addTransaction/components/payee_field.dart index 0d3606f2..663bcaab 100644 --- a/lib/screens/addTransaction/components/payee_field.dart +++ b/lib/screens/addTransaction/components/payee_field.dart @@ -1,10 +1,9 @@ - import 'package:flutter/material.dart'; -import 'package:your_budget/components/rowContainer.dart'; -class PayeeField extends StatelessWidget { +import '../../../components/rowContainer.dart'; - final state; //_AddTransactionPageController +class PayeeField extends StatelessWidget { + final state; //_AddTransactionPageController final TextStyle defaultChildTextStyle; final TextStyle selectedChildTextStyle; diff --git a/lib/screens/addTransaction/components/subcategory_field.dart b/lib/screens/addTransaction/components/subcategory_field.dart index f1dc71ad..8b4fb14a 100644 --- a/lib/screens/addTransaction/components/subcategory_field.dart +++ b/lib/screens/addTransaction/components/subcategory_field.dart @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:your_budget/components/rowContainer.dart'; -import 'package:your_budget/models/entries.dart'; + +import '../../../components/rowContainer.dart'; +import '../../../models/entries.dart'; class SubcategoryField extends StatelessWidget { const SubcategoryField({ From d9eaa5c60089f68c980ad8c2afdb2c7846b1dfec Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 17:45:43 +0100 Subject: [PATCH 10/33] Add transaction ChangeNotifier #5 --- lib/main.dart | 2 ++ lib/screens/addTransaction/addTransactionState.dart | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 lib/screens/addTransaction/addTransactionState.dart diff --git a/lib/main.dart b/lib/main.dart index 1028ceb3..14e81a90 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,6 +7,7 @@ import 'package:your_budget/models/constants.dart'; import 'package:your_budget/screens/addAccount/addAccount.dart'; 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'; @@ -31,6 +32,7 @@ class MyBudget extends StatelessWidget { ChangeNotifierProvider.value(value: GetIt.instance()), // ChangeNotifierProvider(create: (_) => BudgetPageState()) ChangeNotifierProvider(create: (_) => ShowTransactionsState()), + ChangeNotifierProvider(create: (_) => AddTransactionState()), ChangeNotifierProvider(create: (_) => DeleteCategoriesState()), ], child: HomeScreen()); } diff --git a/lib/screens/addTransaction/addTransactionState.dart b/lib/screens/addTransaction/addTransactionState.dart new file mode 100644 index 00000000..ff6dc54c --- /dev/null +++ b/lib/screens/addTransaction/addTransactionState.dart @@ -0,0 +1,7 @@ +import 'package:flutter/foundation.dart'; + +class AddTransactionState extends ChangeNotifier { + + + +} From e7a33bf7065da17376fbc082ede27ff23a4d90f4 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 17:49:00 +0100 Subject: [PATCH 11/33] Extract setPayee() #5 --- lib/screens/addTransaction/addTransaction.dart | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 199987f6..ce6b3ff0 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -124,6 +124,7 @@ class _AddTransactionPageController extends State { @override void dispose() { amountController.dispose(); + memoController.dispose(); super.dispose(); } @@ -138,15 +139,19 @@ class _AddTransactionPageController extends State { builder: (context) => SelectValuePage(title: "Payees", listEntries: payeesAndAccounts)), ).then((returnElement) { - if (returnElement != null) { - setState(() { - payee = returnElement; - payeeFieldName = returnElement.name; - }); - } + if (returnElement != null) + _setPayee(returnElement); + }); } + void _setPayee(returnElement) { + setState(() { + payee = returnElement; + payeeFieldName = returnElement.name; + }); + } + /// When tapping on the [SelectValuePage] widget pertaining /// to the [Account] object, it pushes to the route selecting /// a [Account], whose value is stored in [_account] and whose From f48e739db6e873772f8d619c1ad5cf6b338f158b Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 17:50:39 +0100 Subject: [PATCH 12/33] Extract setAccount() #5 --- lib/screens/addTransaction/addTransaction.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index ce6b3ff0..bce1b3a3 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -164,14 +164,18 @@ class _AddTransactionPageController extends State { SelectValuePage(title: "Accounts", listEntries: accounts)), ).then((returnElement) { if (returnElement != null) { - setState(() { - _account = returnElement; - accountFieldName = returnElement.name; - }); + _setAccount(returnElement); } }); } + void _setAccount(returnElement) { + setState(() { + _account = returnElement; + accountFieldName = returnElement.name; + }); + } + /// When tapping on the [SelectValuePage] widget pertaining /// to the [SubCategory] object, it pushes to the route selecting /// a [SubCategory], whose value is stored in [_subcategory] and whose From 3556b7aeae0ce675a6b5599355cd4b80caeec41d Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 17:52:51 +0100 Subject: [PATCH 13/33] Extract combination of TBB and subcategories #5 --- lib/screens/addTransaction/addTransaction.dart | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index bce1b3a3..245de140 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -185,14 +185,9 @@ class _AddTransactionPageController extends State { context, MaterialPageRoute( builder: (context) { - List subcatAndToBeBudgeted = []; - subcategories.forEach((subcat) { - subcatAndToBeBudgeted.add(subcat); - }); - subcatAndToBeBudgeted.add(Text("To be budgeted")); - return SelectValuePage( - title: "Subcategories", listEntries: subcatAndToBeBudgeted); + title: "Subcategories", + listEntries: _combineSubcategoriesAndToBeBudgeted(),); }, ), ); @@ -207,6 +202,15 @@ class _AddTransactionPageController extends State { } } + List _combineSubcategoriesAndToBeBudgeted() { + List subcatAndToBeBudgeted = []; + subcategories.forEach((subcat) { + subcatAndToBeBudgeted.add(subcat); + }); + subcatAndToBeBudgeted.add(Text("To be budgeted")); + return subcatAndToBeBudgeted; + } + /// When tapping on the Date row, it opens the DataPicker /// which allows one to choose the date as a [DateTime]. /// Defaults to the current day-year-month. From e83552539edbcca58198c897ff1f25ea89ea9256 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 17:53:54 +0100 Subject: [PATCH 14/33] Extract setSubcategory() #5 --- lib/screens/addTransaction/addTransaction.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 245de140..577b02b8 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -193,15 +193,19 @@ class _AddTransactionPageController extends State { ); if (returnElement != null) { - setState(() { - _subcategory = returnElement; - subcategoryFieldName = returnElement is SubCategory - ? returnElement.name - : returnElement.data; - }); + _setSubcategory(returnElement); } } + void _setSubcategory(returnElement) { + setState(() { + _subcategory = returnElement; + subcategoryFieldName = returnElement is SubCategory + ? returnElement.name + : returnElement.data; + }); + } + List _combineSubcategoriesAndToBeBudgeted() { List subcatAndToBeBudgeted = []; subcategories.forEach((subcat) { From c98e9dac9d4f748bee0895170316df845e704623 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 17:55:25 +0100 Subject: [PATCH 15/33] Extract pickDate() #5 --- lib/screens/addTransaction/addTransaction.dart | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 577b02b8..824392b8 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -221,11 +221,7 @@ class _AddTransactionPageController extends State { /// The [DateTime] gets stored in [_date], and the string /// value of that date is saved in [dateFieldName]. Future handleOnTapDate(BuildContext context) async { - DateTime picked = await showDatePicker( - context: context, - initialDate: getDateYMD(_date), - firstDate: appState.startingBudgetDate, - lastDate: getLastDayOfMonth(getMaxBudgetDate())); + DateTime picked = await _pickDate(context); if (picked != null && picked != _date) picked = addExactEntryTime(picked); setState(() { _date = picked; @@ -233,6 +229,15 @@ class _AddTransactionPageController extends State { }); } + Future _pickDate(BuildContext context) async { + DateTime picked = await showDatePicker( + context: context, + initialDate: getDateYMD(_date), + firstDate: appState.startingBudgetDate, + lastDate: getLastDayOfMonth(getMaxBudgetDate())); + return picked; + } + /// Check that all the necessary fields in the form /// specified by [_formKey] have been filled. /// If that is the case, create a new [MoneyTransaction] From 389808bea6744d486d71fed753dba75dbc0e5a1e Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 17:56:22 +0100 Subject: [PATCH 16/33] Extract setDate() #5 --- lib/screens/addTransaction/addTransaction.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 824392b8..663657c8 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -222,6 +222,10 @@ class _AddTransactionPageController extends State { /// value of that date is saved in [dateFieldName]. Future handleOnTapDate(BuildContext context) async { DateTime picked = await _pickDate(context); + _setDate(picked); + } + + void _setDate(DateTime picked) { if (picked != null && picked != _date) picked = addExactEntryTime(picked); setState(() { _date = picked; From 5c9f081deef45780361a0d176d82102632848a62 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 18:01:36 +0100 Subject: [PATCH 17/33] Refactor handleSwitchOnChanged() #5 --- .../addTransaction/addTransaction.dart | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 663657c8..99cffa8d 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -304,18 +304,30 @@ class _AddTransactionPageController extends State { void handleSwitchOnChanged() { setState(() { isPositive = !isPositive; - if (isPositive && amountController.text[0] == '-') - amountController.text = amountController.text.substring(1); - else if (!isPositive) amountController.text = "-" + amountController.text; - - // Change the maximal possible length of the amount to account for - // the minus sign. - amountLength = isPositive ? 16 : 17; - // Lastly, set the offset to the correct position. + + bool positiveWithMinusSign = isPositive && amountController.text[0] == '-'; + if (positiveWithMinusSign) + _removeMinusSign(); + else if (!isPositive) + _addMinusSign(); + + _updateAmountLength(); _setOffsetToLastDigit(); }); } + void _updateAmountLength() { + amountLength = isPositive ? 16 : 17; + } + + void _addMinusSign() { + amountController.text = "-" + amountController.text; + } + + void _removeMinusSign() { + amountController.text = amountController.text.substring(1); + } + /// Checks that the amount of the transaction is not 0. handleAmountValidate(String value) { if (formatCurrencyToDouble(amountController.text, isPositive) == 0) { From edae7051894373e92d0fccc465e35d1a41141b60 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 18:10:04 +0100 Subject: [PATCH 18/33] Refactor handleOnTapDate() #5 --- lib/screens/addTransaction/addTransaction.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 99cffa8d..cf5e9a63 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -339,6 +339,11 @@ class _AddTransactionPageController extends State { /// Reset [amountController.text] to "0.00 €" or "-0.00€", depending on /// the value of [isPositive] handleAmountOnTap() { + _setAmountToZero(); + _setOffsetToLastDigit(); + } + + void _setAmountToZero() { String zero = currencyNumberFormat.format(0).trim(); amountController.text = isPositive ? zero : "-" + zero; _setOffsetToLastDigit(); From 4077f122da4c3cfee59fe66cfc10c5e3d2c5f513 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 18:10:30 +0100 Subject: [PATCH 19/33] Remove Scrollbar not attach to any views #5 --- .../addTransaction/addTransaction.dart | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index cf5e9a63..23d3b394 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -346,7 +346,6 @@ class _AddTransactionPageController extends State { void _setAmountToZero() { String zero = currencyNumberFormat.format(0).trim(); amountController.text = isPositive ? zero : "-" + zero; - _setOffsetToLastDigit(); } /// Set the cursor offset to the last digit of the text. @@ -373,35 +372,31 @@ class _AddTransactionPageView child: Column(children: [ Container( height: 400, - child: Scrollbar( - isAlwaysShown: true, - controller: state._scrollController, - child: Column( - children: [ - Row( - children: [ - Expanded(child: AmountInputContainer(state: state)), - AmountSwitch(state: state), - ], - ), - PayeeField( - state: state, - defaultChildTextStyle: defaultChildTextStyle, - selectedChildTextStyle: selectedChildTextStyle), - AccountField( - state: state, - defaultChildTextStyle: defaultChildTextStyle, - selectedChildTextStyle: selectedChildTextStyle), - SubcategoryField( - state: state, - defaultChildTextStyle: defaultChildTextStyle, - selectedChildTextStyle: selectedChildTextStyle), - DateField( - state: state, - selectedChildTextStyle: selectedChildTextStyle), - MemoField(state: state), - ], - ), + child: Column( + children: [ + Row( + children: [ + Expanded(child: AmountInputContainer(state: state)), + AmountSwitch(state: state), + ], + ), + PayeeField( + state: state, + defaultChildTextStyle: defaultChildTextStyle, + selectedChildTextStyle: selectedChildTextStyle), + AccountField( + state: state, + defaultChildTextStyle: defaultChildTextStyle, + selectedChildTextStyle: selectedChildTextStyle), + SubcategoryField( + state: state, + defaultChildTextStyle: defaultChildTextStyle, + selectedChildTextStyle: selectedChildTextStyle), + DateField( + state: state, + selectedChildTextStyle: selectedChildTextStyle), + MemoField(state: state), + ], )), // TODO: Error message FloatingActionButton( From da20cea3826deed0a64b1a3ada535ce58f2b83d2 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 18:16:58 +0100 Subject: [PATCH 20/33] Refactor addMoneyTransaction() #5 --- .../addTransaction/addTransaction.dart | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 23d3b394..93a52913 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -254,23 +254,11 @@ class _AddTransactionPageController extends State { if (payee != null && _account != null) { _amount = formatCurrencyToDouble(amountController.text, isPositive); - print("Form validated"); - print("Amount : $_amount"); - print("Payee : $payeeFieldName"); - print("Account : $accountFieldName"); - print( - "Subcategory : ${payee is Payee ? 'No subcategory' : subcategoryFieldName}"); - print("Date: $dateFieldName"); - print("Memo : ${memoController.text}"); - - // Input as payee ID the opposite of the account ID when we select - // an account instead of a payee in the 'Payee' field - print("payee is of type ${payee is Payee ? "Payee" : "Account"}"); - int payeeId = payee is Payee ? payee.id : -_account.id; + _printTransactionInformation(); appState.addTransaction( subcatId: _selectSubcatId(), - payeeId: payeeId, + payeeId: _selectPayeeId(), accountId: _account.id, amount: _amount, memo: memoController.text, @@ -285,6 +273,26 @@ class _AddTransactionPageController extends State { } } + void _printTransactionInformation() { + print("Form validated"); + print("Amount : $_amount"); + print("Payee : $payeeFieldName"); + print("Account : $accountFieldName"); + print( + "Subcategory : ${payee is Payee ? 'No subcategory' : subcategoryFieldName}"); + print("Date: $dateFieldName"); + print("Memo : ${memoController.text}"); + + // Input as payee ID the opposite of the account ID when we select + // an account instead of a payee in the 'Payee' field + print("payee is of type ${payee is Payee ? "Payee" : "Account"}"); + } + + int _selectPayeeId() { + int payeeId = payee is Payee ? payee.id : -_account.id; + return payeeId; + } + _selectSubcatId() { bool subcategoryIsToBeBudgeted = subcategoryFieldName == "To be budgeted"; if (payee is Payee && !subcategoryIsToBeBudgeted) From 27ba49e4cbcc2a7df2fef83051c303c67851c2dc Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 18:20:05 +0100 Subject: [PATCH 21/33] Remove .then() flow #5 --- .../addTransaction/addTransaction.dart | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 93a52913..01ca50b7 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -133,16 +133,15 @@ class _AddTransactionPageController extends State { /// a [Payee], whose value is stored in [payee] and whose /// name is stored in [payeeFieldName]. handleOnTapPayee() { - Navigator.push( + var returnElement = Navigator.push( context, MaterialPageRoute( builder: (context) => SelectValuePage(title: "Payees", listEntries: payeesAndAccounts)), - ).then((returnElement) { - if (returnElement != null) - _setPayee(returnElement); + ); - }); + if (returnElement != null) + _setPayee(returnElement); } void _setPayee(returnElement) { @@ -157,16 +156,15 @@ class _AddTransactionPageController extends State { /// a [Account], whose value is stored in [_account] and whose /// name is stored in [accountFieldName]. handleOnTapAccount() { - Navigator.push( + var returnElement = Navigator.push( context, MaterialPageRoute( builder: (context) => SelectValuePage(title: "Accounts", listEntries: accounts)), - ).then((returnElement) { - if (returnElement != null) { - _setAccount(returnElement); - } - }); + ); + + if (returnElement != null) + _setAccount(returnElement); } void _setAccount(returnElement) { @@ -181,7 +179,7 @@ class _AddTransactionPageController extends State { /// a [SubCategory], whose value is stored in [_subcategory] and whose /// name is stored in [subcategoryFieldName]. handleOnTapCategory() async { - dynamic returnElement = await Navigator.push( + var returnElement = await Navigator.push( context, MaterialPageRoute( builder: (context) { @@ -192,9 +190,9 @@ class _AddTransactionPageController extends State { ), ); - if (returnElement != null) { + if (returnElement != null) _setSubcategory(returnElement); - } + } void _setSubcategory(returnElement) { @@ -307,8 +305,6 @@ class _AddTransactionPageController extends State { _amount = formatCurrencyToDouble(amountController.text, isPositive); } - // When the switch is set to the 'off' position, the text style changes - // and a minus sign is added in front of the text. void handleSwitchOnChanged() { setState(() { isPositive = !isPositive; @@ -336,7 +332,6 @@ class _AddTransactionPageController extends State { amountController.text = amountController.text.substring(1); } - /// Checks that the amount of the transaction is not 0. handleAmountValidate(String value) { if (formatCurrencyToDouble(amountController.text, isPositive) == 0) { return "Value must be different than 0"; @@ -344,8 +339,6 @@ class _AddTransactionPageController extends State { return null; } - /// Reset [amountController.text] to "0.00 €" or "-0.00€", depending on - /// the value of [isPositive] handleAmountOnTap() { _setAmountToZero(); _setOffsetToLastDigit(); @@ -355,8 +348,6 @@ class _AddTransactionPageController extends State { String zero = currencyNumberFormat.format(0).trim(); amountController.text = isPositive ? zero : "-" + zero; } - - /// Set the cursor offset to the last digit of the text. _setOffsetToLastDigit() { amountController.selection = TextSelection.collapsed(offset: amountController.text.length - 2); From c0bdae9f11bc7455ec3bcc27aa6048bf568e81e1 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 18:20:36 +0100 Subject: [PATCH 22/33] Remove scrollController variable #5 --- lib/screens/addTransaction/addTransaction.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 01ca50b7..12401784 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -37,7 +37,6 @@ class _AddTransactionPageController extends State { final _formKey = GlobalKey(); final TextEditingController memoController = new TextEditingController(); - final ScrollController _scrollController = new ScrollController(); /// Default names will have a different style than selected ones final String defaultPayeeFieldName = "Select payee"; From 9a5bdd5b668591be02581f177ec3d842249abffd Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 20 Dec 2020 18:21:06 +0100 Subject: [PATCH 23/33] Format addTransaction.dart #5 --- .../addTransaction/addTransaction.dart | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 12401784..62799534 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -139,15 +139,14 @@ class _AddTransactionPageController extends State { SelectValuePage(title: "Payees", listEntries: payeesAndAccounts)), ); - if (returnElement != null) - _setPayee(returnElement); + if (returnElement != null) _setPayee(returnElement); } void _setPayee(returnElement) { setState(() { - payee = returnElement; - payeeFieldName = returnElement.name; - }); + payee = returnElement; + payeeFieldName = returnElement.name; + }); } /// When tapping on the [SelectValuePage] widget pertaining @@ -162,8 +161,7 @@ class _AddTransactionPageController extends State { SelectValuePage(title: "Accounts", listEntries: accounts)), ); - if (returnElement != null) - _setAccount(returnElement); + if (returnElement != null) _setAccount(returnElement); } void _setAccount(returnElement) { @@ -183,15 +181,14 @@ class _AddTransactionPageController extends State { MaterialPageRoute( builder: (context) { return SelectValuePage( - title: "Subcategories", - listEntries: _combineSubcategoriesAndToBeBudgeted(),); + title: "Subcategories", + listEntries: _combineSubcategoriesAndToBeBudgeted(), + ); }, ), ); - if (returnElement != null) - _setSubcategory(returnElement); - + if (returnElement != null) _setSubcategory(returnElement); } void _setSubcategory(returnElement) { @@ -308,11 +305,11 @@ class _AddTransactionPageController extends State { setState(() { isPositive = !isPositive; - bool positiveWithMinusSign = isPositive && amountController.text[0] == '-'; + bool positiveWithMinusSign = + isPositive && amountController.text[0] == '-'; if (positiveWithMinusSign) _removeMinusSign(); - else if (!isPositive) - _addMinusSign(); + else if (!isPositive) _addMinusSign(); _updateAmountLength(); _setOffsetToLastDigit(); @@ -347,6 +344,7 @@ class _AddTransactionPageController extends State { String zero = currencyNumberFormat.format(0).trim(); amountController.text = isPositive ? zero : "-" + zero; } + _setOffsetToLastDigit() { amountController.selection = TextSelection.collapsed(offset: amountController.text.length - 2); From dbd765d44b67964b3ecb1b2fd21f03f7eb7dc12a Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 10:36:25 +0100 Subject: [PATCH 24/33] Fix payees not being updated after creation After adding a payee using 'Create payee', although the new payee was saved in the AppState, this change was not visible when selecting a new payee again because the list of payees (and accounts) sent to SelectValue are done in initState. Now, it is done in handleOnTapPayee, which makes it so that the payees and accounts are fetched from AppState every time we click on the Payee field. --- .../addTransaction/addTransaction.dart | 15 +++++--------- lib/screens/addTransaction/selectValue.dart | 20 +++++++++---------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 62799534..03a961ee 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -61,10 +61,7 @@ class _AddTransactionPageController extends State { /// List of values to choose each value from, e.g. [payee] /// will be chosen from one of the [payees] - List payees; List subcategories; - List accounts; - List payeesAndAccounts = []; AppState appState; @override @@ -76,13 +73,7 @@ class _AddTransactionPageController extends State { amountLength = 16; // Load list of objects from the state/database appState = Provider.of(context, listen: false); - payees = appState.payees; - accounts = appState.accounts; subcategories = appState.subcategories; - - payeesAndAccounts.addAll(payees); - payeesAndAccounts.addAll(accounts); - // Set initial values of the transaction payee = null; _account = null; @@ -132,6 +123,10 @@ class _AddTransactionPageController extends State { /// a [Payee], whose value is stored in [payee] and whose /// name is stored in [payeeFieldName]. handleOnTapPayee() { + List payeesAndAccounts = []; + payeesAndAccounts.addAll(appState.payees); + payeesAndAccounts.addAll(appState.accounts); + var returnElement = Navigator.push( context, MaterialPageRoute( @@ -158,7 +153,7 @@ class _AddTransactionPageController extends State { context, MaterialPageRoute( builder: (context) => - SelectValuePage(title: "Accounts", listEntries: accounts)), + SelectValuePage(title: "Accounts", listEntries: appState.accounts)), ); if (returnElement != null) _setAccount(returnElement); diff --git a/lib/screens/addTransaction/selectValue.dart b/lib/screens/addTransaction/selectValue.dart index 10e358e3..22920bc7 100644 --- a/lib/screens/addTransaction/selectValue.dart +++ b/lib/screens/addTransaction/selectValue.dart @@ -53,18 +53,18 @@ class SelectValuePageState extends State { @override Widget build(BuildContext context) { - return new Scaffold( + return Scaffold( resizeToAvoidBottomInset: false, - appBar: new AppBar( + appBar: AppBar( title: Text(widget.title), ), - body: new Column( + body: Column( children: [ - new Padding( - padding: new EdgeInsets.only(top: 20.0), + Padding( + padding: EdgeInsets.only(top: 20.0), ), - new TextField( - decoration: new InputDecoration( + TextField( + decoration: InputDecoration( hintText: "Search something", icon: Icon(Icons.search), ), @@ -81,8 +81,8 @@ class SelectValuePageState extends State { onTap: () => handleCreateNewPayee(filter), ), - new Expanded( - child: new ListView.separated( + Expanded( + child: ListView.separated( shrinkWrap: true, itemCount: widget.listEntries.length, separatorBuilder: (BuildContext context, int index) => @@ -102,7 +102,7 @@ class SelectValuePageState extends State { return ListTile(title: item, onTap: () => handlePopContext(item)); } // There is an error - return new Container(); + return Container(); }, )) ], From dbf481a8e321119509bd44da8ffed6730e4e9211 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 10:50:24 +0100 Subject: [PATCH 25/33] Await Navigator.push #5 --- lib/screens/addTransaction/addTransaction.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 03a961ee..16049147 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -122,18 +122,18 @@ class _AddTransactionPageController extends State { /// to the [Payee] object, it pushes to the route selecting /// a [Payee], whose value is stored in [payee] and whose /// name is stored in [payeeFieldName]. - handleOnTapPayee() { - List payeesAndAccounts = []; + handleOnTapPayee() async { + List payeesAndAccounts = []; payeesAndAccounts.addAll(appState.payees); payeesAndAccounts.addAll(appState.accounts); - var returnElement = Navigator.push( + var returnElement = await Navigator.push( context, MaterialPageRoute( builder: (context) => SelectValuePage(title: "Payees", listEntries: payeesAndAccounts)), ); - + print(returnElement); if (returnElement != null) _setPayee(returnElement); } @@ -148,8 +148,8 @@ class _AddTransactionPageController extends State { /// to the [Account] object, it pushes to the route selecting /// a [Account], whose value is stored in [_account] and whose /// name is stored in [accountFieldName]. - handleOnTapAccount() { - var returnElement = Navigator.push( + handleOnTapAccount() async { + var returnElement = await Navigator.push( context, MaterialPageRoute( builder: (context) => From f5f110545bc64da0ad5ae198f92492f50c801d20 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 11:10:21 +0100 Subject: [PATCH 26/33] Fix between account transactions Closes #16 --- lib/screens/addTransaction/addTransaction.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 16049147..5ca714fb 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -278,7 +278,7 @@ class _AddTransactionPageController extends State { } int _selectPayeeId() { - int payeeId = payee is Payee ? payee.id : -_account.id; + int payeeId = payee is Payee ? payee.id : -payee.id; return payeeId; } From f0dffbb1466494ea8f03afd6edfd5f6f08edbf28 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sat, 2 Jan 2021 12:12:40 +0100 Subject: [PATCH 27/33] Fix typo in 'Electricity' --- lib/models/database_provider.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models/database_provider.dart b/lib/models/database_provider.dart index 7ddb8cc8..a463b1e0 100644 --- a/lib/models/database_provider.dart +++ b/lib/models/database_provider.dart @@ -168,7 +168,7 @@ class DatabaseProvider { int categoryId = await db.rawInsert(CREATE_CATEGORY, ["Essentials"]); - List subcategoryNames = ["Rent", "Eletricity", "Water", "Food", "Internet", "Phone"]; + List subcategoryNames = ["Rent", "Electricity", "Water", "Food", "Internet", "Phone"]; List subcategoryIds = []; for (int i = 0; i < subcategoryNames.length; i++) { int subcategoryId = await db.rawInsert(CREATE_SUBCATEGORY, [categoryId, subcategoryNames[i]]); From ff395cd8df5d5617a2c59ad98b2400a52d09af09 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 3 Jan 2021 11:38:07 +0100 Subject: [PATCH 28/33] Set default value for integers and decimals This removes the need to check for null when the budgeted value gets deleted to 1 character or less. #29 --- .../addTransaction/components/CurrencyInputFormatter.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/screens/addTransaction/components/CurrencyInputFormatter.dart b/lib/screens/addTransaction/components/CurrencyInputFormatter.dart index 31fa2467..a8dad78b 100644 --- a/lib/screens/addTransaction/components/CurrencyInputFormatter.dart +++ b/lib/screens/addTransaction/components/CurrencyInputFormatter.dart @@ -5,7 +5,8 @@ import 'package:intl/intl.dart'; /// this method returns the double value of [currencyText], making sure /// it is positive when [isPositive] is true, and negative when not. double formatCurrencyToDouble(String currencyText, bool isPositive) { - String integers, decimals; + String integers = "0"; + String decimals = "0"; String onlyNumbers = currencyText.replaceAll(RegExp('[^0-9]'), ''); int textLength = onlyNumbers.length; From 41ff10a2073f9cd55fe1a412f35b81927f647786 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Sun, 3 Jan 2021 12:19:06 +0100 Subject: [PATCH 29/33] Fix the dates in addSubcategory loop Previously, the last month from getMaxBudgetDate() was not included. Now it is. #28 --- lib/appState.dart | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/appState.dart b/lib/appState.dart index ea8cfea3..23e9209c 100644 --- a/lib/appState.dart +++ b/lib/appState.dart @@ -132,6 +132,10 @@ class AppState extends ChangeNotifier { /// extracting the subcategories of each [MainCategory] from /// scratch void addSubcategory(SubCategoryModel subcategoryModel) async { + DateTime newDate = startingBudgetDate; + DateTime maxBudgetDate = getMaxBudgetDate(); + DateTime previousDate; + int subcatId = await queryContext.addSubcategory(subcategoryModel); SubCategory subcategory = SubCategory( subcatId, @@ -147,26 +151,28 @@ class AppState extends ChangeNotifier { /// Insert a budget value for every month from [startingBudgetDate] until [MAX_NB_MONTHS_AHEAD] /// after [DateTime.now()], - for (int i = 0; - i < Constants.MAX_NB_MONTHS_AHEAD + getMonthDifference(startingBudgetDate, DateTime.now()); - i++) { + do { /// Update BudgetValues - DateTime newDate = Jiffy(startingBudgetDate).add(months: i); + + previousDate = newDate; BudgetValueModel budgetValueModel = BudgetValueModel( subcategoryId: subcatId, budgeted: 0, available: 0, - year: newDate.year, - month: newDate.month, + year: previousDate.year, + month: previousDate.month, ); int budgetId = await queryContext.addBudgetValue(budgetValueModel); BudgetValue budgetValue = - BudgetValue(budgetId, subcategory.id, 0, 0, newDate.year, newDate.month); + BudgetValue(budgetId, subcategory.id, 0, 0, previousDate.year, previousDate.month); _budgetValues.add(budgetValue); - } + newDate = Jiffy(previousDate).add(months: 1); + + } while(previousDate.isBefore(maxBudgetDate)); + notifyListeners(); } From 44cb0f27cc419d5c0d94c18ce05a60bcd74a508e Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Tue, 5 Jan 2021 20:19:29 +0100 Subject: [PATCH 30/33] Show transaction success or error using SnackBar #25, #15 --- .../addTransaction/addTransaction.dart | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 48c6ceb2..be5ece73 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -213,17 +213,32 @@ class _AddTransactionPageController extends State { /// with the information entered, add the transaction and /// reset the whole [AddTransactionPage] to the default values /// and display a notification. - void addMoneyTransaction() async { + void addMoneyTransaction(BuildContext context) async { _formKey.currentState.save(); if (_formKey.currentState.validate()) { - if (_payee != null && _account != null) { + + bool isNegativeTransactionsIntoToBeBudgeted = !isPositive && _subcategoryFieldName == "To be budgeted"; + bool isPositiveTranasctionsIntoSubcategory = isPositive && !(_payee is Account) && _subcategoryFieldName != "To be budgeted"; + + if (isNegativeTransactionsIntoToBeBudgeted){ + SnackBar snackbar = SnackBar(content: Text("Can't have negative transaction on to be budgeted", style: TextStyle(color: Colors.white),), backgroundColor: Colors.red,); + Scaffold.of(context).showSnackBar(snackbar); + + } + else if (isPositiveTranasctionsIntoSubcategory){ + SnackBar snackbar = SnackBar(content: Text("Positive transactions should go into to be budgeted", style: TextStyle(color: Colors.white),), backgroundColor: Colors.red,); + Scaffold.of(context).showSnackBar(snackbar); + + } + + else if (_payee != null && _account != null) { _amount = formatCurrencyToDouble(_amountController.text, isPositive); print("Form validated"); print("Amount : $_amount"); print("Payee : $_payeeFieldName"); print("Account : $_accountFieldName"); - print("Subcategory : ${_payee is Payee ? 'No subcategory' : _subcategoryFieldName}"); + print("Subcategory : ${_payee is Payee ? _subcategoryFieldName : 'No subcategory'}"); print("Date: $_dateFieldName"); print("Memo : ${_memoController.text}"); @@ -242,8 +257,10 @@ class _AddTransactionPageController extends State { ); resetToDefaultTransaction(); - showOverlayNotification(context, "Transaction added"); - } else { + SnackBar snackbar = SnackBar(content: Text("Transaction added", style: TextStyle(color: Colors.white),), backgroundColor: Colors.green,); + Scaffold.of(context).showSnackBar(snackbar); + } + else { print("One of the fields does not contain a valid type"); } } @@ -314,7 +331,7 @@ class _AddTransactionPageView TextStyle(color: Colors.grey, fontStyle: FontStyle.italic, fontSize: 16.0); final TextStyle selectedChildTextStyle = TextStyle(color: Colors.black, fontSize: 16.0); - Widget _myBuildMethod() { + Widget _myBuildMethod(BuildContext context) { // Create number controller /// This [TextFormField] handles the amount selected while providing /// an intuitive experience to the user, who does not need to manually @@ -433,7 +450,7 @@ class _AddTransactionPageView // TODO: Error message FloatingActionButton( child: Text("Enter"), - onPressed: () => state.addMoneyTransaction(), + onPressed: () => state.addMoneyTransaction(context), ) ]), ); @@ -460,7 +477,7 @@ class _AddTransactionPageView } else { return Form( key: state._formKey, - child: _myBuildMethod(), + child: _myBuildMethod(context), ); } })); From ec73e27611b8969c4060efabf22f38316e527998 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Tue, 5 Jan 2021 21:20:38 +0100 Subject: [PATCH 31/33] Fix AmountInputContainer sliding up on error #11 --- lib/screens/addTransaction/addTransaction.dart | 1 - .../addTransaction/components/amount_input_container.dart | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index 00cd1ef6..e252ec0e 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -388,7 +388,6 @@ class _AddTransactionPageView return SingleChildScrollView( child: Column(children: [ Container( - height: 400, child: Column( children: [ Row( diff --git a/lib/screens/addTransaction/components/amount_input_container.dart b/lib/screens/addTransaction/components/amount_input_container.dart index b70ca0e3..3e1da565 100644 --- a/lib/screens/addTransaction/components/amount_input_container.dart +++ b/lib/screens/addTransaction/components/amount_input_container.dart @@ -30,12 +30,13 @@ class AmountInputContainer extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - height: 50, alignment: Alignment.centerRight, - padding: new EdgeInsets.symmetric(horizontal: 10.0), + padding: EdgeInsets.symmetric(horizontal: 10.0), child: TextFormField( - decoration: new InputDecoration.collapsed( + decoration: InputDecoration( hintText: "", + helperText: "", + enabledBorder: InputBorder.none, ), keyboardType: TextInputType.number, controller: state.amountController, From a76acaa1fb7a8d26f6c9df257c25f97bbe34a0f4 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Tue, 5 Jan 2021 22:16:16 +0100 Subject: [PATCH 32/33] Update CHANGELOG.md --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75a2fe40..7789c02a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## Version 1.1.4 + +- 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 +- BUGFIX: Fix amount field sliding up when having an error in the Add Transaction tab +- FEATURE: Transaction success or error is now shown using SnackBars +- REFACTOR: [WIP] Refactor addTransactionScreen + ## Version 1.1.3 - BUGFIX: To Be budgeted now gets updated directly after transaction From f7f61061eabe9763598b3630f45a71ecab6463d0 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Tue, 5 Jan 2021 22:16:41 +0100 Subject: [PATCH 33/33] Bump version to 1.2.0+14 --- pubspec.yaml | 2 +- version.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 6b8f9cff..97ba35c0 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.1.3+13 +version: 1.2.0+14 environment: sdk: ">=2.7.0 <3.0.0" diff --git a/version.txt b/version.txt index e1eb7a41..b25194fd 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.1.3+13 +1.2.0+14