From 938b4a93f7968c94ec2054528e8c361450bd9df8 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Fri, 6 Dec 2024 06:00:24 +0530 Subject: [PATCH] Show error snackbar on import failure --- lib/screens/home_page/collection_pane.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/screens/home_page/collection_pane.dart b/lib/screens/home_page/collection_pane.dart index 3105a63a..75708db4 100644 --- a/lib/screens/home_page/collection_pane.dart +++ b/lib/screens/home_page/collection_pane.dart @@ -19,6 +19,7 @@ class CollectionPane extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final collection = ref.watch(collectionStateNotifierProvider); + var sm = ScaffoldMessenger.of(context); if (collection == null) { return const Center( child: CircularProgressIndicator(), @@ -47,7 +48,7 @@ class CollectionPane extends ConsumerWidget { }, onFileDropped: (file) { final importFormatType = ref.read(importFormatStateProvider); - String? msg; + sm.hideCurrentSnackBar(); file.readAsString().then( (content) { kImporter @@ -58,18 +59,17 @@ class CollectionPane extends ConsumerWidget { .read(collectionStateNotifierProvider.notifier) .addRequestModel(importedRequestModel); } else { - msg = "Unable to parse ${file.name}"; + var err = "Unable to parse ${file.name}"; + sm.showSnackBar(getSnackBar(err, small: false)); } }); }, onError: (e) { - msg = "Unable to import ${file.name}"; + var err = "Unable to import ${file.name}"; + sm.showSnackBar(getSnackBar(err, small: false)); }, ); Navigator.of(context).pop(); - if (msg != null) { - showTextDialog(context, content: msg); - } }, ); },