From 27ffb07256fcfb86db89cb75dc807b66728d7498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=BCller?= Date: Mon, 1 Apr 2024 13:57:12 +0200 Subject: [PATCH] added dialog when location is disabled --- lib/view/home.dart | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/view/home.dart b/lib/view/home.dart index 349c056..5ae3b53 100644 --- a/lib/view/home.dart +++ b/lib/view/home.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:app/extensions/obtainProviderExtension.dart'; import 'package:app/extensions/positionLatLngExtension.dart'; import 'package:app/state/mapState.dart'; @@ -32,14 +34,42 @@ class _HomePageState extends State { }); }); - requestLiveLocation(context.obtainState(), false, true, true); + requestLiveLocation(false, true, true); } - Future requestLiveLocation(MapState mapState, bool ask, bool orLast, bool loadingIndicator) async { + Future requestLiveLocation(bool ask, bool orLast, bool loadingIndicator) async { Position? position; + MapState mapState = context.obtainState(); LocationPermission permission = await Geolocator.checkPermission(); + log(permission.toString()); - if (loadingIndicator && permission != LocationPermission.deniedForever) { + if( + permission == LocationPermission.denied + || permission == LocationPermission.deniedForever + || permission == LocationPermission.unableToDetermine + ) { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text("Standort"), + content: const Text("Dein Standort konnte nicht bestimmt werden.\nAktiviere für die Standortbestimmung deinen Standort und gib der App die entsprechenden Berechtigungen."), + actions: [ + TextButton( + onPressed: () => Navigator.of(context).pop(), + child: const Text("Okay"), + ) + ], + ); + } + ); + } + + if ( + loadingIndicator + && permission != LocationPermission.deniedForever + && permission != LocationPermission.denied + ) { setState(() { locationLoading = true; }); @@ -125,7 +155,7 @@ class _HomePageState extends State { } return const Icon(Icons.location_disabled); }), - onPressed: () => requestLiveLocation(context.obtainState(), true, false, true), + onPressed: () => requestLiveLocation(true, false, true), ), body: Column( children: [