Skip to content

Commit

Permalink
Corrections
Browse files Browse the repository at this point in the history
  - Fixes the case when the floating action button is pressed while
    viewing a transactions-only account (was just a placeholder snackbar
before). Now takes user to txn form with the toAccount populated
correctly
  - Renders newly created txns in list after saving (`listen: true`)
  - Displays "No transactions." if an account has none in the TxnsView
    widget
  • Loading branch information
Nick Tyler authored and Nick Tyler committed Mar 11, 2021
1 parent 9ff45ea commit a29f22b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/widgets/account_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AccountView extends StatelessWidget {
body: TabBarView(
children: [
ListOfAccounts(accounts: this.account.children),
TransactionsView(transactions: Provider.of<TransactionsModel>(context, listen: false).transactionsByAccountFullName[this.account.fullName] ?? [])
TransactionsView(transactions: Provider.of<TransactionsModel>(context, listen: true).transactionsByAccountFullName[this.account.fullName] ?? [])
],
),
floatingActionButton: Builder(builder: (context) {
Expand Down
34 changes: 26 additions & 8 deletions lib/widgets/list_of_accounts.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:gnucash_mobile/providers/accounts.dart';
import 'package:gnucash_mobile/providers/transactions.dart';
import 'package:gnucash_mobile/widgets/transaction_form.dart';
import 'package:gnucash_mobile/widgets/transactions_view.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -31,9 +32,11 @@ class ListOfAccounts extends StatelessWidget {

final _account = this.accounts[i];
final List<Transaction> _transactions = [];
for (var key in transactionsModel.transactionsByAccountFullName.keys) {
for (var key
in transactionsModel.transactionsByAccountFullName.keys) {
if (key.startsWith(_account.fullName)) {
_transactions.addAll(transactionsModel.transactionsByAccountFullName[key]);
_transactions.addAll(
transactionsModel.transactionsByAccountFullName[key]);
}
}
final double _balance = _transactions.fold(0.0,
Expand All @@ -57,16 +60,31 @@ class ListOfAccounts extends StatelessWidget {
title: Text(_account.fullName),
),
body: TransactionsView(
transactions: _transactions,
),
transactions: Provider.of<TransactionsModel>(
context,
listen: true)
.transactionsByAccountFullName[
_account.fullName] ??
[]),
floatingActionButton: Builder(builder: (context) {
return FloatingActionButton(
backgroundColor: Constants.darkBG,
child: Icon(Icons.add),
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"You tapped the transactions-only button!")));
onPressed: () async {
final _success = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TransactionForm(
toAccount: _account,
),
),
);

if (_success != null && _success) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Transaction created!")));
}
},
);
}),
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/transactions_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class TransactionsView extends StatelessWidget {
);

return Container(
child: _transactionsBuilder,
child: this.transactions.length > 0
? _transactionsBuilder
: Center(child: Text("No transactions.")),
);
});
}
Expand Down

0 comments on commit a29f22b

Please sign in to comment.