From 966179d01de442f7879720cb38a8d45b3a70bee6 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Fri, 2 May 2025 11:07:44 +0200 Subject: [PATCH] Added mounted check to popups --- lib/views/information_view.dart | 78 +++++++++++++++++---------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/lib/views/information_view.dart b/lib/views/information_view.dart index 6b99e4c..0236427 100644 --- a/lib/views/information_view.dart +++ b/lib/views/information_view.dart @@ -83,46 +83,50 @@ class InformationView extends StatelessWidget { ], ), CupertinoButton( - sizeStyle: CupertinoButtonSize.medium, - child: const Text('Spieldaten exportieren'), - onPressed: () async => - await LocalStorageService.exportJsonFile() - ? null - : showCupertinoDialog( - context: context, - builder: (context) => CupertinoAlertDialog( - title: const Text('Fehler'), - content: const Text( - 'Datei konnte nicht exportiert werden.'), - actions: [ - CupertinoDialogAction( - child: const Text('OK'), - onPressed: () => - Navigator.pop(context), - ), - ], - ))), + sizeStyle: CupertinoButtonSize.medium, + child: const Text('Spieldaten exportieren'), + onPressed: () async { + final success = await LocalStorageService.exportJsonFile(); + if (!success && context.mounted) { + showCupertinoDialog( + context: context, + builder: (context) => CupertinoAlertDialog( + title: const Text('Fehler'), + content: const Text( + 'Datei konnte nicht exportiert werden.'), + actions: [ + CupertinoDialogAction( + child: const Text('OK'), + onPressed: () => Navigator.pop(context), + ), + ], + ), + ); + } + }, + ), CupertinoButton( sizeStyle: CupertinoButtonSize.medium, child: const Text('Spieldaten importieren'), - onPressed: () async => { - await LocalStorageService.importJsonFile() - ? null - : showCupertinoDialog( - context: context, - builder: (context) => CupertinoAlertDialog( - title: const Text('Fehler'), - content: const Text( - 'Datei konnte nicht importiert werden.'), - actions: [ - CupertinoDialogAction( - child: const Text('OK'), - onPressed: () => - Navigator.pop(context), - ), - ], - )) - }), + onPressed: () async { + final success = + await LocalStorageService.importJsonFile(); + if (!success && context.mounted) { + showCupertinoDialog( + context: context, + builder: (context) => CupertinoAlertDialog( + title: const Text('Fehler'), + content: const Text( + 'Datei konnte nicht importiert werden.'), + actions: [ + CupertinoDialogAction( + child: const Text('OK'), + onPressed: () => Navigator.pop(context), + ), + ], + )); + } + }), ], ), Positioned(