Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix/187: update account after updating transaction #188

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions lib/pages/add_page/add_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../constants/functions.dart';
import '../../constants/style.dart';
import '../../model/transaction.dart';
import '../../providers/accounts_provider.dart';
import '../../providers/transactions_provider.dart';
import "widgets/account_selector.dart";
import 'widgets/amount_section.dart';
Expand Down Expand Up @@ -87,6 +88,12 @@ class _AddPageState extends ConsumerState<AddPage> with Functions {
}
}

void _updateAccount() {
ref
.read(accountsProvider.notifier)
.updateAccount(ref.watch(bankAccountProvider)!.name);
}

void _createOrUpdateTransaction() {
final selectedType = ref.read(transactionTypeProvider);
final selectedTransaction = ref.read(selectedTransactionUpdateProvider);
Expand Down Expand Up @@ -143,9 +150,20 @@ class _AddPageState extends ConsumerState<AddPage> with Functions {
}
}
}

_updateAccount();
}
}

void _deleteTransaction() {
final selectedTransaction = ref.read(selectedTransactionUpdateProvider);
ref
.read(transactionsProvider.notifier)
.deleteTransaction(selectedTransaction!.id!)
.whenComplete(() => Navigator.pop(context));
_updateAccount();
}

@override
Widget build(BuildContext context) {
final selectedType = ref.watch(transactionTypeProvider);
Expand Down Expand Up @@ -175,12 +193,7 @@ class _AddPageState extends ConsumerState<AddPage> with Functions {
Icons.delete_outline,
color: Theme.of(context).colorScheme.error,
),
onPressed: () async {
ref
.read(transactionsProvider.notifier)
.deleteTransaction(selectedTransaction.id!)
.whenComplete(() => Navigator.pop(context));
},
onPressed: _deleteTransaction,
),
)
: const SizedBox(),
Expand Down
Loading