Extend permission denied handling functionality to location toggle tracking in main screen
This commit is contained in:
parent
6bd94cf4db
commit
a7a34ffd6c
1 changed files with 24 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:app_settings/app_settings.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:traccar_client/main.dart';
|
import 'package:traccar_client/main.dart';
|
||||||
|
|
@ -73,6 +74,13 @@ class _MainScreenState extends State<MainScreen> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isPermissionDeniedError(PlatformException error) {
|
||||||
|
final errorDetails = '${error.code} ${error.message ?? ''}'.toLowerCase();
|
||||||
|
return errorDetails.contains('denied') ||
|
||||||
|
errorDetails.contains('permission_denied') ||
|
||||||
|
errorDetails.contains('access_denied');
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildTrackingCard() {
|
Widget _buildTrackingCard() {
|
||||||
return Card(
|
return Card(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
|
|
@ -105,7 +113,22 @@ class _MainScreenState extends State<MainScreen> {
|
||||||
_checkBatteryOptimizations(context);
|
_checkBatteryOptimizations(context);
|
||||||
}
|
}
|
||||||
} on PlatformException catch (error) {
|
} on PlatformException catch (error) {
|
||||||
messengerKey.currentState?.showSnackBar(SnackBar(content: Text(error.message ?? error.code)));
|
final isPermissionError = isPermissionDeniedError(error);
|
||||||
|
if (!mounted) return;
|
||||||
|
messengerKey.currentState?.showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(error.message ?? error.code),
|
||||||
|
duration: const Duration(seconds: 4),
|
||||||
|
action: isPermissionError
|
||||||
|
? SnackBarAction(
|
||||||
|
label: AppLocalizations.of(context)!.settingsTitle,
|
||||||
|
onPressed: () => AppSettings.openAppSettings(
|
||||||
|
type: AppSettingsType.settings,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FirebaseCrashlytics.instance.log('tracking_toggle_stop');
|
FirebaseCrashlytics.instance.log('tracking_toggle_stop');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue