From 95cd9efad296889d108b7034078079015c7ffd34 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 10:36:25 +0100 Subject: [PATCH 01/13] 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 | 16 ++++++--------- lib/screens/addTransaction/selectValue.dart | 20 +++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/screens/addTransaction/addTransaction.dart b/lib/screens/addTransaction/addTransaction.dart index afe6cfb9..dca952c5 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; @@ -129,6 +120,11 @@ 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); + Navigator.push( context, MaterialPageRoute( @@ -151,7 +147,7 @@ class _AddTransactionPageController extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => SelectValuePage(title: "Accounts", listEntries: accounts)), + builder: (context) => SelectValuePage(title: "Accounts", listEntries: appState.accounts)), ).then((returnElement) { if (returnElement != null) { setState(() { diff --git a/lib/screens/addTransaction/selectValue.dart b/lib/screens/addTransaction/selectValue.dart index 750d1552..759f17d2 100644 --- a/lib/screens/addTransaction/selectValue.dart +++ b/lib/screens/addTransaction/selectValue.dart @@ -68,18 +68,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), ), @@ -98,8 +98,8 @@ class SelectValuePageState extends State { context: context, defaultName: searchController.text), ), - new Expanded( - child: new ListView.separated( + Expanded( + child: ListView.separated( shrinkWrap: true, itemCount: widget.listEntries.length, separatorBuilder: (BuildContext context, int index) => @@ -121,7 +121,7 @@ class SelectValuePageState extends State { title: item, onTap: () => handlePopContext(item)); } // There is an error - return new Container(); + return Container(); }, )) ], From b9d63b3736c7c55c388673ce1e1c37d271a24fc7 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 11:10:21 +0100 Subject: [PATCH 02/13] 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 dca952c5..041943ad 100644 --- a/lib/screens/addTransaction/addTransaction.dart +++ b/lib/screens/addTransaction/addTransaction.dart @@ -229,7 +229,7 @@ class _AddTransactionPageController extends State { // 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; + int payeeId = _payee is Payee ? _payee.id : -_payee.id; appState.addTransaction( subcatId: _selectSubcatId(), From 2827cbcf6c6479f8feb0c5eba97a4583cd6200d5 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 11:34:54 +0100 Subject: [PATCH 03/13] Go to new line after printing MoneyTransaction #17 --- lib/models/entries.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models/entries.dart b/lib/models/entries.dart index f678a115..ab2109a6 100644 --- a/lib/models/entries.dart +++ b/lib/models/entries.dart @@ -85,7 +85,7 @@ class MoneyTransaction { @override String toString() { return super.toString() + - """ {id: $id, subcatID: $subcatID, payeeID: $payeeID, accountID: $accountID, amount: $amount, date: $date}"""; + """{id: $id, subcatID: $subcatID, payeeID: $payeeID, accountID: $accountID, amount: $amount, date: $date}\n"""; } } From 977b698233b7f85df5ad51bb6b884d8c24b8d6be Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 12:09:05 +0100 Subject: [PATCH 04/13] Create copy() method in MoneyTransaction #17 --- lib/models/entries.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/models/entries.dart b/lib/models/entries.dart index ab2109a6..57a8875c 100644 --- a/lib/models/entries.dart +++ b/lib/models/entries.dart @@ -87,6 +87,17 @@ class MoneyTransaction { return super.toString() + """{id: $id, subcatID: $subcatID, payeeID: $payeeID, accountID: $accountID, amount: $amount, date: $date}\n"""; } + + MoneyTransaction copy() { + return MoneyTransaction( + id: this.id, + subcatID: this.subcatID, + payeeID: this.payeeID, + accountID: this.accountID, + amount: this.amount, + memo: this.memo, + date: this.date); + } } /// Class representing the physical account where the money is stored. From d1b03d10abcd5630411cebd98c00bb737d68a999 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 12:44:17 +0100 Subject: [PATCH 05/13] Fix amountTextStyle not changing after every rebuild #17 --- .../components/transactionRow.dart | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/screens/showTransactions/components/transactionRow.dart b/lib/screens/showTransactions/components/transactionRow.dart index 93a3e11a..571bc3b5 100644 --- a/lib/screens/showTransactions/components/transactionRow.dart +++ b/lib/screens/showTransactions/components/transactionRow.dart @@ -28,22 +28,16 @@ class _TransactionRowState extends State { final TextStyle subcategoryStyle = TextStyle(fontSize: 16.0, fontWeight: FontWeight.w600, color: Colors.black); - TextStyle amountStyle; - - void initState() { - amountStyle = TextStyle( + @override + Widget build(BuildContext context) { + String subcategoryName = ""; + String payeeName; + TextStyle amountStyle = TextStyle( fontSize: 22.0, fontWeight: FontWeight.w600, color: widget.moneyTransaction.amount.isNegative ? Constants.RED_COLOR : Constants.GREEN_COLOR); - super.initState(); - } - - @override - Widget build(BuildContext context) { - String subcategoryName = ""; - String payeeName; AppState appState = Provider.of(context, listen: false); if (appState.payees.isNotEmpty) { From 62a49d12082d5a2548d3be4167bd72df4f184d8c Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 12:50:22 +0100 Subject: [PATCH 06/13] Extract _setPayeeName() method #17 --- .../components/transactionRow.dart | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/screens/showTransactions/components/transactionRow.dart b/lib/screens/showTransactions/components/transactionRow.dart index 571bc3b5..6c99ea32 100644 --- a/lib/screens/showTransactions/components/transactionRow.dart +++ b/lib/screens/showTransactions/components/transactionRow.dart @@ -32,7 +32,7 @@ class _TransactionRowState extends State { Widget build(BuildContext context) { String subcategoryName = ""; String payeeName; - TextStyle amountStyle = TextStyle( + TextStyle amountStyle = TextStyle( fontSize: 22.0, fontWeight: FontWeight.w600, color: widget.moneyTransaction.amount.isNegative @@ -40,15 +40,7 @@ class _TransactionRowState extends State { : Constants.GREEN_COLOR); AppState appState = Provider.of(context, listen: false); - if (appState.payees.isNotEmpty) { - // orElse is for starting balance - Payee payee = appState.payees - .singleWhere((payee) => payee.id == widget.moneyTransaction.payeeID, orElse: () => null); - - payeeName = payee != null ? payee.name : ""; - } else { - payeeName = ""; - } + payeeName = _setPayeeName(appState); /// Extract name of subcategory associated to transaction [moneyTransaction] if (widget.moneyTransaction.subcatID == Constants.UNASSIGNED_SUBCAT_ID) { @@ -93,4 +85,15 @@ class _TransactionRowState extends State { payeeName, subcategoryStyle); } + + String _setPayeeName(AppState appState) { + if (appState.payees.isNotEmpty) { + // orElse is for starting balance + Payee payee = appState.payees + .singleWhere((payee) => payee.id == widget.moneyTransaction.payeeID, orElse: () => null); + + return payee != null ? payee.name : ""; + } + return ""; + } } From 59b5d3fc4adcb727b061c68bcf0320acfabf9dd6 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 12:52:51 +0100 Subject: [PATCH 07/13] Extract _setSubcategoryName() method #17 --- .../components/transactionRow.dart | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/lib/screens/showTransactions/components/transactionRow.dart b/lib/screens/showTransactions/components/transactionRow.dart index 6c99ea32..cb27d565 100644 --- a/lib/screens/showTransactions/components/transactionRow.dart +++ b/lib/screens/showTransactions/components/transactionRow.dart @@ -41,26 +41,7 @@ class _TransactionRowState extends State { AppState appState = Provider.of(context, listen: false); payeeName = _setPayeeName(appState); - - /// Extract name of subcategory associated to transaction [moneyTransaction] - if (widget.moneyTransaction.subcatID == Constants.UNASSIGNED_SUBCAT_ID) { - // Transfer between accounts - for (final Account account in appState.accounts) { - if (account.id == -widget.moneyTransaction.payeeID) { - subcategoryName = "To/From " + account.name; - } - } - } else if (widget.moneyTransaction.subcatID == - Constants.TO_BE_BUDGETED_ID_IN_MONEYTRANSACTION) { - //Transaction into to be budgeted - subcategoryName = "To be budgeted"; - } else { - // Transaction into subcategories - var correspondingSubcategory = widget.categories.singleWhere( - ((cat) => cat is SubCategory && cat.id == widget.moneyTransaction.subcatID), - orElse: () => null); - subcategoryName = correspondingSubcategory != null ? correspondingSubcategory.name : ""; - } + subcategoryName = _setSubcategoryName(appState); return widget.isEditable ? CheckedRow( @@ -86,6 +67,28 @@ class _TransactionRowState extends State { subcategoryStyle); } + String _setSubcategoryName(AppState appState) { + /// Extract name of subcategory associated to transaction [moneyTransaction] + if (widget.moneyTransaction.subcatID == Constants.UNASSIGNED_SUBCAT_ID) { + // Transfer between accounts + for (final Account account in appState.accounts) { + if (account.id == -widget.moneyTransaction.payeeID) { + return "To/From " + account.name; + } + } + } else if (widget.moneyTransaction.subcatID == + Constants.TO_BE_BUDGETED_ID_IN_MONEYTRANSACTION) { + //Transaction into to be budgeted + return "To be budgeted"; + } + // Transaction into subcategories + var correspondingSubcategory = widget.categories.singleWhere( + ((cat) => cat is SubCategory && cat.id == widget.moneyTransaction.subcatID), + orElse: () => null); + return correspondingSubcategory != null ? correspondingSubcategory.name : ""; + + } + String _setPayeeName(AppState appState) { if (appState.payees.isNotEmpty) { // orElse is for starting balance From 45fa3ace4950df6c23af3cffab700d9089ae1e8b Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 13:02:06 +0100 Subject: [PATCH 08/13] Fix minor code formatting --- lib/appState.dart | 9 ++++++--- lib/models/entries.dart | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/appState.dart b/lib/appState.dart index ac628787..ebb061ce 100644 --- a/lib/appState.dart +++ b/lib/appState.dart @@ -225,9 +225,12 @@ class AppState extends ChangeNotifier { await computeToBeBudgeted(); notifyListeners(); } else if (transaction.subcatID == Constants.UNASSIGNED_SUBCAT_ID) { - // If the transaction amount is positive, the transaction will remove money from - // outAccount and input it into inAccount. - // Otherwise, it is reversed. + /// If the transaction amount is positive, the transaction will remove money from + /// [outAccount] and input it into [inAccount]. + /// Otherwise, it is reversed. + + /// [outAccount] is ALWAYS the one pointed to by accountID. + /// Therefore, [inAccount] will be the one defined by [-payee.id]. final Account outAccount = accounts.singleWhere((account) => account.id == transaction.accountID); outAccount.balance -= transaction.amount; diff --git a/lib/models/entries.dart b/lib/models/entries.dart index 57a8875c..83041386 100644 --- a/lib/models/entries.dart +++ b/lib/models/entries.dart @@ -1,4 +1,3 @@ - /// This file will contain the classes for the common objects used throughout the codebase, namely /// [Payee], [MoneyTransaction], and [Account]. @@ -79,7 +78,8 @@ class MoneyTransaction { this.accountID = json[DatabaseConstants.ACCOUNT_ID_OUTSIDE]; this.amount = json[DatabaseConstants.MONEYTRANSACTION_AMOUNT]; this.memo = json[DatabaseConstants.MONEYTRANSACTION_MEMO]; - this.date = DateTime.fromMillisecondsSinceEpoch(json[DatabaseConstants.MONEYTRANSACTION_DATE]); + this.date = DateTime.fromMillisecondsSinceEpoch( + json[DatabaseConstants.MONEYTRANSACTION_DATE]); } @override From ebf9564798b839884da0aeae1b12d17047d19134 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 13:03:34 +0100 Subject: [PATCH 09/13] Make every transaction show up in both accounts #17 --- .../components/transactionList.dart | 55 ++++++++++++++++--- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/lib/screens/showTransactions/components/transactionList.dart b/lib/screens/showTransactions/components/transactionList.dart index a86c187b..604f2b74 100644 --- a/lib/screens/showTransactions/components/transactionList.dart +++ b/lib/screens/showTransactions/components/transactionList.dart @@ -1,5 +1,8 @@ +import 'dart:collection'; + import 'package:flutter/material.dart'; import 'package:your_budget/appState.dart'; +import 'package:your_budget/models/constants.dart'; import 'package:your_budget/models/entries.dart'; import 'package:your_budget/screens/showTransactions/components/transactionRow.dart'; @@ -25,15 +28,15 @@ class _TransactionListState extends State { @override Widget build(BuildContext context) { - List transactionsOfAccount = widget.appState.transactions - .where((transaction) => transaction.accountID == this.widget.account.id) - .toList(); + List transactionsOfAccount = + _computeToFromMoneyTransactions( + widget.appState.transactions, this.widget.account.id); - return new Container( + return Container( child: Scrollbar( isAlwaysShown: true, controller: _scrollController, - child: new ListView.separated( + child: ListView.separated( controller: _scrollController, shrinkWrap: true, itemCount: transactionsOfAccount.length, @@ -41,10 +44,48 @@ class _TransactionListState extends State { Divider(height: 1, color: Colors.black12), itemBuilder: (BuildContext context, int index) { return Card( - child: TransactionRow( - transactionsOfAccount[index], widget.appState.allCategories, widget.isEditable)); + child: TransactionRow(transactionsOfAccount[index], + widget.appState.allCategories, widget.isEditable)); }, ), )); } } + +List _computeToFromMoneyTransactions( + UnmodifiableListView transactions, int currentAccountId) { + /// Here, [currentAccountId] is the outgoingAccount. + + List transactionsOfAccount = []; + for (var transaction in transactions) { + bool isStandardPayee = transaction.payeeID > 0; + bool isAccountPayee = transaction.payeeID < 0; + bool isStartingBalanceTransaction = + transaction.payeeID == Constants.UNASSIGNED_PAYEE_ID; + + bool currentAccountIsPayeeAccount = + -transaction.payeeID == currentAccountId; + bool currentAccountIsStandardAccount = + transaction.accountID == currentAccountId; + + bool isPositiveTransaction = transaction.amount > 0; + bool isNegativeTransaction = !isPositiveTransaction; + + if (isStartingBalanceTransaction && currentAccountIsStandardAccount) + transactionsOfAccount.add(transaction); + if (currentAccountIsStandardAccount && + isStandardPayee && + !isStartingBalanceTransaction) + transactionsOfAccount.add(transaction); + else if ((currentAccountIsStandardAccount && isAccountPayee)) { + // The transaction is reversed.i.e. removes money from outAccount(accountId) + // into inAccount(payeeId) + MoneyTransaction negativeAmountTransaction = transaction.copy(); + negativeAmountTransaction.amount *= -1; + transactionsOfAccount.add(negativeAmountTransaction); + } else if (currentAccountIsPayeeAccount && isAccountPayee) + transactionsOfAccount.add(transaction); + } + + return transactionsOfAccount; +} From d3bf704d8d9338551eb5542f829cf2639dab1f9f Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 13:16:09 +0100 Subject: [PATCH 10/13] Refactor _computeToFromMoneyTransactions() method #17 --- .../components/transactionList.dart | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/screens/showTransactions/components/transactionList.dart b/lib/screens/showTransactions/components/transactionList.dart index 604f2b74..84e3b3cd 100644 --- a/lib/screens/showTransactions/components/transactionList.dart +++ b/lib/screens/showTransactions/components/transactionList.dart @@ -58,33 +58,23 @@ List _computeToFromMoneyTransactions( List transactionsOfAccount = []; for (var transaction in transactions) { - bool isStandardPayee = transaction.payeeID > 0; bool isAccountPayee = transaction.payeeID < 0; - bool isStartingBalanceTransaction = - transaction.payeeID == Constants.UNASSIGNED_PAYEE_ID; bool currentAccountIsPayeeAccount = -transaction.payeeID == currentAccountId; bool currentAccountIsStandardAccount = transaction.accountID == currentAccountId; - bool isPositiveTransaction = transaction.amount > 0; - bool isNegativeTransaction = !isPositiveTransaction; - - if (isStartingBalanceTransaction && currentAccountIsStandardAccount) - transactionsOfAccount.add(transaction); - if (currentAccountIsStandardAccount && - isStandardPayee && - !isStartingBalanceTransaction) + if ((currentAccountIsStandardAccount && !isAccountPayee) || + (currentAccountIsPayeeAccount && isAccountPayee)) { transactionsOfAccount.add(transaction); - else if ((currentAccountIsStandardAccount && isAccountPayee)) { + } else if ((currentAccountIsStandardAccount && isAccountPayee)) { // The transaction is reversed.i.e. removes money from outAccount(accountId) // into inAccount(payeeId) MoneyTransaction negativeAmountTransaction = transaction.copy(); negativeAmountTransaction.amount *= -1; transactionsOfAccount.add(negativeAmountTransaction); - } else if (currentAccountIsPayeeAccount && isAccountPayee) - transactionsOfAccount.add(transaction); + } } return transactionsOfAccount; From 535a5590688c8f564a9b337781b9998914d993f1 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 13:17:36 +0100 Subject: [PATCH 11/13] Rename _computeToFromMoneyTransactions() Renamed it to _getMoneyTransactions(). #17 --- lib/screens/showTransactions/components/transactionList.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/screens/showTransactions/components/transactionList.dart b/lib/screens/showTransactions/components/transactionList.dart index 84e3b3cd..b12f3c6b 100644 --- a/lib/screens/showTransactions/components/transactionList.dart +++ b/lib/screens/showTransactions/components/transactionList.dart @@ -29,7 +29,7 @@ class _TransactionListState extends State { @override Widget build(BuildContext context) { List transactionsOfAccount = - _computeToFromMoneyTransactions( + _getMoneyTransactions( widget.appState.transactions, this.widget.account.id); return Container( @@ -52,7 +52,7 @@ class _TransactionListState extends State { } } -List _computeToFromMoneyTransactions( +List _getMoneyTransactions( UnmodifiableListView transactions, int currentAccountId) { /// Here, [currentAccountId] is the outgoingAccount. From 4ef70c81a89830d5a1067ee3203b5ec795628641 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 13:23:13 +0100 Subject: [PATCH 12/13] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c0d7c3a..574de4c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Version 1.1.2 + +- BUGFIX: Transactions between accounts now appear in both accounts + ## Version 1.1.1 - FEATURE: Creating new payee show a dialog From 3152bfa0d745b0bcb953a7f3c0ae729cae8071f1 Mon Sep 17 00:00:00 2001 From: Tom Crasset Date: Fri, 1 Jan 2021 13:23:47 +0100 Subject: [PATCH 13/13] Bump version to 1.1.2+12 --- pubspec.yaml | 2 +- version.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 5a86b868..a63140da 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.1+11 +version: 1.1.2+12 environment: sdk: ">=2.7.0 <3.0.0" diff --git a/version.txt b/version.txt index eb9a4385..328308ff 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.1.1+11 +1.1.2+12