ERROR_ALREADY_REQUESTING_PERMISSIONS on flutter
The thing is when it checks for permission it returns null instead of any of the Permission status, which results in a exception. It could possibly a bug multiple people have filled issues related to Location permission.
https://github.com/BaseflowIT/flutter-geolocator/issues/172
https://github.com/BaseflowIT/flutter-geolocator/issues/
https://github.com/BaseflowIT/flutter-permission-handler/issues
void getPermissionStatus() async {
PermissionStatus permission = await PermissionHandler()
.checkPermissionStatus(PermissionGroup.storage);
if (permission == PermissionStatus.granted) {
} // ideally you should specify another condition if permissions is denied
else if (permission == PermissionStatus.denied ||
permission == PermissionStatus.disabled ||
permission == PermissionStatus.restricted) {
await PermissionHandler().requestPermissions([PermissionGroup.storage]);
getPermissionStatus();
}
}
I don't think there is problem with your code anyway you can use recursion instead of creating two separate functions.
Ashtav
I am fullstack developer, I write code and also make music, I love to play guitar, drum, violin and piano.
Updated on December 11, 2022Comments
-
Ashtav over 1 year
I create an android app with flutter, I create permission request at the first time when app is run, so when user click deny and then click login button, permission requested again. I got this error
Exception has occurred. PlatformException (PlatformException(ERROR_ALREADY_REQUESTING_PERMISSIONS, A request for permissions is already running, please wait for it to finish before doing another request (note that you can request multiple permissions at the same time)., null))
this is my code
@override void initState() { this.setSharedPreferences(); PermissionHandler().checkPermissionStatus(PermissionGroup.location).then(_checkPermission); } void _checkPermission(PermissionStatus status){ if(status == PermissionStatus.unknown || status == PermissionStatus.denied){ _askPermission(); } } void _askPermission() async{ await PermissionHandler().requestPermissions([PermissionGroup.location]); } void onLogin() async { PermissionStatus locationPermission = await PermissionHandler().checkPermissionStatus(PermissionGroup.location); if(locationPermission == PermissionStatus.denied || locationPermission == PermissionStatus.unknown){ _askPermission(); }else{ // user available to login } }
How to handle this? thanks for your answer
-
Dhaval Kansara about 4 years@NdeemSiddhique While getting location permission if Permission status is disabled means App has location permission but the location of that device is of then Is there any way to guide user for turn on location of that device.
-
dcg about 4 yearsThis is a very dangerous solution! it can easily result in an infinity loop, which would crash the app.
-
Nadeem Siddique about 4 yearsNot an infinite loop exactly but it won't let the user get past until it allows the permission. Depends on usercase but I agree it's not idle. I'll update it.
-
Arbaz kdr over 3 yearsCan some one please write this same code with latest version of the permission_handler: ^5.0.1+1