Check permission denial using background geolocation provider state instead of platform exception based string matching
This commit is contained in:
parent
a7a34ffd6c
commit
e309a7729a
1 changed files with 5 additions and 6 deletions
|
|
@ -74,11 +74,10 @@ class _MainScreenState extends State<MainScreen> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPermissionDeniedError(PlatformException error) {
|
Future<bool> _isPermissionDenied() async {
|
||||||
final errorDetails = '${error.code} ${error.message ?? ''}'.toLowerCase();
|
final providerState = await bg.BackgroundGeolocation.providerState;
|
||||||
return errorDetails.contains('denied') ||
|
return providerState.status == bg.ProviderChangeEvent.AUTHORIZATION_STATUS_DENIED ||
|
||||||
errorDetails.contains('permission_denied') ||
|
providerState.status == bg.ProviderChangeEvent.AUTHORIZATION_STATUS_RESTRICTED;
|
||||||
errorDetails.contains('access_denied');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildTrackingCard() {
|
Widget _buildTrackingCard() {
|
||||||
|
|
@ -113,7 +112,7 @@ class _MainScreenState extends State<MainScreen> {
|
||||||
_checkBatteryOptimizations(context);
|
_checkBatteryOptimizations(context);
|
||||||
}
|
}
|
||||||
} on PlatformException catch (error) {
|
} on PlatformException catch (error) {
|
||||||
final isPermissionError = isPermissionDeniedError(error);
|
final isPermissionError = await _isPermissionDenied();
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
messengerKey.currentState?.showSnackBar(
|
messengerKey.currentState?.showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue