From 092a6008c01ce7900027bfe4199abaceaa5ee07b Mon Sep 17 00:00:00 2001
From: Florian <74116125+florianschndlr@users.noreply.github.com>
Date: Mon, 3 Jul 2023 12:10:12 +0200
Subject: [PATCH] delete button in transaction modal working

---
 .../frontend/utils/transaction_listtile.dart  | 55 ++++++++++---------
 1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/trackeroo/lib/frontend/utils/transaction_listtile.dart b/trackeroo/lib/frontend/utils/transaction_listtile.dart
index 4e5ba2e..eb5e299 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()
+        ),
+      )
+    );
+  }
 }
-- 
GitLab