From 71a8c68309e75c22e492bc96b489848e64d5cc78 Mon Sep 17 00:00:00 2001 From: Nico Date: Wed, 4 Jun 2025 22:43:39 +0200 Subject: [PATCH] now shows correct position on first start of tracking --- lib/screens/excursion/excursion_main.dart | 7 ++++--- lib/screens/helper/add_entries_dialog_helper.dart | 15 ++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/screens/excursion/excursion_main.dart b/lib/screens/excursion/excursion_main.dart index 8859a39..db37b3b 100644 --- a/lib/screens/excursion/excursion_main.dart +++ b/lib/screens/excursion/excursion_main.dart @@ -125,7 +125,7 @@ class _ExcursionMainState extends State { void initState() { GeolocatorService.deteterminePosition( alwaysOnNeeded: true, - ).then((result) => currentPosition = result).catchError((error) { + ).then((result) => currentPosition = result).catchError((error) async { if (error is LocationDisabledException) { if (mounted) { SnackBarHelper.showSnackBarMessage( @@ -142,8 +142,9 @@ class _ExcursionMainState extends State { } } else if (error is NeedAlwaysLocation) { if (mounted) { - AddEntriesDialogHelper.locationSettingsDialog(context); - } + bool reload = await AddEntriesDialogHelper.locationSettingsDialog(context); + if (reload) GeolocatorService.deteterminePosition().then((res) => currentPosition = res).catchError((error) {return currentPosition;}); +} } return currentPosition; }); diff --git a/lib/screens/helper/add_entries_dialog_helper.dart b/lib/screens/helper/add_entries_dialog_helper.dart index 5a880c1..ce5fb13 100644 --- a/lib/screens/helper/add_entries_dialog_helper.dart +++ b/lib/screens/helper/add_entries_dialog_helper.dart @@ -303,8 +303,11 @@ class AddEntriesDialogHelper { ); } - static void locationSettingsDialog(BuildContext context) async { - return showDialog( + static Future locationSettingsDialog(BuildContext context) async { + + bool reload = false; + + await showDialog( context: context, barrierDismissible: true, builder: (BuildContext context) { @@ -312,9 +315,10 @@ class AddEntriesDialogHelper { content: Text(AppLocalizations.of(context)!.needsAlwaysLocation), actions: [ TextButton( - onPressed: () { - Geolocator.openAppSettings(); - Navigator.pop(context); + onPressed: () async { + await Geolocator.openAppSettings(); + if (context.mounted) Navigator.pop(context); + reload = true; }, child: Text("Ok"), ), @@ -328,6 +332,7 @@ class AddEntriesDialogHelper { ); }, ); + return reload; } static Future deleteCompleteRouteDialog(BuildContext context) async {