added guide that explains to the user how to give always location permission
This commit is contained in:
@@ -124,7 +124,7 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
||||
@override
|
||||
void initState() {
|
||||
GeolocatorService.deteterminePosition(
|
||||
alwaysOnNeeded: true,
|
||||
alwaysOnNeeded: false,
|
||||
).then((result) => currentPosition = result).catchError((error) async {
|
||||
if (error is LocationDisabledException) {
|
||||
if (mounted) {
|
||||
@@ -142,9 +142,16 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
||||
}
|
||||
} else if (error is NeedAlwaysLocation) {
|
||||
if (mounted) {
|
||||
bool reload = await AddEntriesDialogHelper.locationSettingsDialog(context);
|
||||
if (reload) GeolocatorService.deteterminePosition().then((res) => currentPosition = res).catchError((error) {return currentPosition;});
|
||||
}
|
||||
bool reload =
|
||||
await AddEntriesDialogHelper.locationSettingsDialog(context);
|
||||
if (reload) {
|
||||
GeolocatorService.deteterminePosition()
|
||||
.then((res) => currentPosition = res)
|
||||
.catchError((error) {
|
||||
return currentPosition;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentPosition;
|
||||
});
|
||||
@@ -346,6 +353,62 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
||||
// ---------- Tracking
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
// Check for always permission before starting tracking
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission != LocationPermission.always) {
|
||||
if (mounted) {
|
||||
bool? shouldContinue = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(AppLocalizations.of(context)!.trackingPermissionTitle),
|
||||
content: Text(AppLocalizations.of(context)!.trackingPermissionContent),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: Text(AppLocalizations.of(context)!.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await Geolocator.openAppSettings();
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.openSettings),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (shouldContinue != true) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait for user to change settings and return
|
||||
// Try checking the permission multiple times
|
||||
for (int i = 0; i < 5; i++) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
if (!mounted) return;
|
||||
|
||||
permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.always) {
|
||||
break;
|
||||
}
|
||||
|
||||
// If this is the last attempt and we still don't have permission
|
||||
if (i == 4 && permission != LocationPermission.always) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.permissionNotGranted),
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return Tracking(
|
||||
@@ -356,8 +419,7 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
||||
));
|
||||
setState(() {});
|
||||
},
|
||||
child:
|
||||
Text(AppLocalizations.of(context)!.trackingAnAusschalten),
|
||||
child: Text(AppLocalizations.of(context)!.trackingAnAusschalten),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
@@ -461,29 +523,32 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
||||
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvoked: (didPop) async {
|
||||
onPopInvokedWithResult: (bool didPop, Object? res) async {
|
||||
if (didPop) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Show confirmation dialog
|
||||
final result = await showDialog<int>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Seite verlassen?'),
|
||||
content: const Text('Möchten Sie die Seite wirklich verlassen?'),
|
||||
title: Text(AppLocalizations.of(context)!.leavePageTitle),
|
||||
content: Text(AppLocalizations.of(context)!.leavePageContent),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(0),
|
||||
child: const Text('Nein'),
|
||||
child: Text(AppLocalizations.of(context)!.nein),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(1),
|
||||
child: const Text('Ja und Template speichern'),
|
||||
onPressed: () {
|
||||
saveTemplate(getFieldsText(), DatabasesEnum.excursion);
|
||||
Navigator.of(context).pop(1);
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.leaveAndSaveTemplate),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(2),
|
||||
child: const Text('Ja ohne Template'),
|
||||
child: Text(AppLocalizations.of(context)!.leaveWithoutSaving),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -517,9 +582,11 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
||||
actions: [
|
||||
// Text(TrackingService().isTracking ? "Tracking" : "Not tracking")
|
||||
Image.asset(
|
||||
TrackingService().isTracking ? "assets/icons/tracking_on.png" : "assets/icons/tracking_off.png",
|
||||
TrackingService().isTracking
|
||||
? "assets/icons/tracking_on.png"
|
||||
: "assets/icons/tracking_off.png",
|
||||
width: 40,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: PageTransitionSwitcher(
|
||||
|
||||
Reference in New Issue
Block a user