diff --git a/trackeroo/lib/frontend/utils/transaction_listtile.dart b/trackeroo/lib/frontend/utils/transaction_listtile.dart index 4e5ba2ea98c3c77acbd1b89e189caffde8a4badd..eb5e29955e8d05ea51a176519adc393232ac41bd 100644 --- a/trackeroo/lib/frontend/utils/transaction_listtile.dart +++ b/trackeroo/lib/frontend/utils/transaction_listtile.dart @@ -28,30 +28,7 @@ class _TransactionListtileState extends State<TransactionListtile> { child: Dismissible( key: UniqueKey(), direction: DismissDirection.startToEnd, - onDismissed: (_) => { - setState(() { - locator.get<TransactionsController>().deleteTransaction(widget.transaction); - }), - ScaffoldMessenger.of(context).removeCurrentSnackBar(), - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - 'Transaction deleted', - style: TextStyle( - color: Theme.of(context).colorScheme.onSecondary - ), - ), - backgroundColor: Theme.of(context).colorScheme.secondary, - behavior: SnackBarBehavior.floating, - shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))), - action: SnackBarAction( - label: 'Undo', - textColor: Theme.of(context).colorScheme.onSecondary, - onPressed: () => locator.get<TransactionsController>().undoLastDeletion() - ), - ) - ) - }, + onDismissed: (_) => deleteTransaction(context), background: Container( padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0), color: Theme.of(context).colorScheme.errorContainer, @@ -181,7 +158,10 @@ class _TransactionListtileState extends State<TransactionListtile> { children: [ Expanded( child: FilledButton.tonal( - onPressed: () => {}, + onPressed: () { + deleteTransaction(context); + Navigator.of(context).pop(); + }, child: const Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -225,4 +205,29 @@ class _TransactionListtileState extends State<TransactionListtile> { ), ); } + + void deleteTransaction(BuildContext context) { + setState(() { + locator.get<TransactionsController>().deleteTransaction(widget.transaction); + }); + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + 'Transaction deleted', + style: TextStyle( + color: Theme.of(context).colorScheme.onSecondary + ), + ), + backgroundColor: Theme.of(context).colorScheme.secondary, + behavior: SnackBarBehavior.floating, + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))), + action: SnackBarAction( + label: 'Undo', + textColor: Theme.of(context).colorScheme.onSecondary, + onPressed: () => locator.get<TransactionsController>().undoLastDeletion() + ), + ) + ); + } }