now shows correct position on first start of tracking

This commit is contained in:
Nico
2025-06-04 22:43:39 +02:00
parent ef5faf7d3d
commit 71a8c68309
2 changed files with 14 additions and 8 deletions

View File

@@ -125,7 +125,7 @@ class _ExcursionMainState extends State<ExcursionMain> {
void initState() { void initState() {
GeolocatorService.deteterminePosition( GeolocatorService.deteterminePosition(
alwaysOnNeeded: true, alwaysOnNeeded: true,
).then((result) => currentPosition = result).catchError((error) { ).then((result) => currentPosition = result).catchError((error) async {
if (error is LocationDisabledException) { if (error is LocationDisabledException) {
if (mounted) { if (mounted) {
SnackBarHelper.showSnackBarMessage( SnackBarHelper.showSnackBarMessage(
@@ -142,8 +142,9 @@ class _ExcursionMainState extends State<ExcursionMain> {
} }
} else if (error is NeedAlwaysLocation) { } else if (error is NeedAlwaysLocation) {
if (mounted) { 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; return currentPosition;
}); });

View File

@@ -303,8 +303,11 @@ class AddEntriesDialogHelper {
); );
} }
static void locationSettingsDialog(BuildContext context) async { static Future<bool> locationSettingsDialog(BuildContext context) async {
return showDialog(
bool reload = false;
await showDialog(
context: context, context: context,
barrierDismissible: true, barrierDismissible: true,
builder: (BuildContext context) { builder: (BuildContext context) {
@@ -312,9 +315,10 @@ class AddEntriesDialogHelper {
content: Text(AppLocalizations.of(context)!.needsAlwaysLocation), content: Text(AppLocalizations.of(context)!.needsAlwaysLocation),
actions: [ actions: [
TextButton( TextButton(
onPressed: () { onPressed: () async {
Geolocator.openAppSettings(); await Geolocator.openAppSettings();
Navigator.pop(context); if (context.mounted) Navigator.pop(context);
reload = true;
}, },
child: Text("Ok"), child: Text("Ok"),
), ),
@@ -328,6 +332,7 @@ class AddEntriesDialogHelper {
); );
}, },
); );
return reload;
} }
static Future<bool> deleteCompleteRouteDialog(BuildContext context) async { static Future<bool> deleteCompleteRouteDialog(BuildContext context) async {