From fb5139f615f428545fdf715be6164dfb6e598013 Mon Sep 17 00:00:00 2001 From: Sara <sarasdj@stud.ntnu.no> Date: Thu, 18 Apr 2024 14:39:01 +0200 Subject: [PATCH] fix: snackbar sucess messages --- app/lib/widgets/main_layout.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/lib/widgets/main_layout.dart b/app/lib/widgets/main_layout.dart index 80e31e63..6f4ce657 100644 --- a/app/lib/widgets/main_layout.dart +++ b/app/lib/widgets/main_layout.dart @@ -191,8 +191,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ), child: const Text("Export JSON"), onPressed: () { - Navigator.of(context).pop(); - // Show progress indicator + // Close bottom sheet before displaying progress bar showProgressIndicator(context); }, @@ -294,6 +293,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { } } +// Saves all measurements to a file on the users mobile device Future<void> _exportIceData() async { final directory = await getExternalStorageDirectory(); final file = File('${directory?.path}/ice_data_$selectedLake.json'); @@ -306,7 +306,6 @@ Future<void> _exportIceData() async { } - // Display a progress indicator while JSON data is being downloaded void showProgressIndicator(BuildContext context) { BuildContext? dialogContext; @@ -333,9 +332,8 @@ void showProgressIndicator(BuildContext context) { ); // Ensure that the progress indicator runs for at lest 1 second - // before exporting the data - Future.delayed(const Duration(milliseconds: 1000), () { - try { + Future.delayed(const Duration(seconds: 1), () { + try { // Download JSON data _exportIceData(); ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Downloaded ice data as JSON')), @@ -349,6 +347,7 @@ void showProgressIndicator(BuildContext context) { // Add 2 second delay before closing the dialog Future.delayed(const Duration(seconds: 2), () { Navigator.of(dialogContext!).pop(); + Navigator.of(context).pop(); }); } } -- GitLab