Show error snackbar on import failure

This commit is contained in:
Ashita Prasad
2024-12-06 06:00:24 +05:30
parent accd3f9771
commit 938b4a93f7

View File

@@ -19,6 +19,7 @@ class CollectionPane extends ConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final collection = ref.watch(collectionStateNotifierProvider); final collection = ref.watch(collectionStateNotifierProvider);
var sm = ScaffoldMessenger.of(context);
if (collection == null) { if (collection == null) {
return const Center( return const Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
@@ -47,7 +48,7 @@ class CollectionPane extends ConsumerWidget {
}, },
onFileDropped: (file) { onFileDropped: (file) {
final importFormatType = ref.read(importFormatStateProvider); final importFormatType = ref.read(importFormatStateProvider);
String? msg; sm.hideCurrentSnackBar();
file.readAsString().then( file.readAsString().then(
(content) { (content) {
kImporter kImporter
@@ -58,18 +59,17 @@ class CollectionPane extends ConsumerWidget {
.read(collectionStateNotifierProvider.notifier) .read(collectionStateNotifierProvider.notifier)
.addRequestModel(importedRequestModel); .addRequestModel(importedRequestModel);
} else { } else {
msg = "Unable to parse ${file.name}"; var err = "Unable to parse ${file.name}";
sm.showSnackBar(getSnackBar(err, small: false));
} }
}); });
}, },
onError: (e) { 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(); Navigator.of(context).pop();
if (msg != null) {
showTextDialog(context, content: msg);
}
}, },
); );
}, },