flutter-permission-handler
                                
                                 flutter-permission-handler copied to clipboard
                                
                                    flutter-permission-handler copied to clipboard
                            
                            
                            
                        [PermissionRequestInProgressException] A request for permissions is already running
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).
Hi @MagdyEl-Sayed, is it possible for you to share your code so I can see where this messages comes from? If you want to ask multiple permissions at the same time, you should request them as follow:
Map<Permission, PermissionStatus> statuses = await [
  Permission.location,
  Permission.storage,
].request();
print(statuses[Permission.location]);
I hope this helped you out, let me know if it worked!
if i select denied and request permission again , it return exception message "request for permissions is already running"
Hi @MagdyEl-Sayed, can you share some more information please?
I would like to see a minimal code snippet to reproduce the issue and the flutter doctor -v output.
if i select denied and request permission again , it return exception message "request for permissions is already running"
same here, exception is thrown for the deny-case only.
final Permission _permission = Permission.locationWhenInUse;
final PermissionStatus status = await _permission.status;
if (!status.isLimited && !status.isGranted) {
  // Ask user for permission. If it has already been granted before, nothing happens
  final PermissionStatus result = await _permission.request();
  if (result.isPermanentlyDenied) {
    onPermanentlyDenied.call();
    return;
  }
  if (!result.isGranted) {
    return;
  }
}
onGranted.call();
flutter doctor -v
[√] Flutter (Channel stable, 2.8.1, on Microsoft Windows [Version 10.0.18363.1977], locale de-DE) • Flutter version 2.8.1 at C:_Apps\Tools\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 77d935af4d (6 weeks ago), 2021-12-16 08:37:33 -0800 • Engine revision 890a5fca2e • Dart version 2.15.1
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at C:_Apps\Tools\Android\SDK • Platform android-31, build-tools 31.0.0 • ANDROID_HOME = C:_Apps\Tools\Android\SDK • ANDROID_SDK_ROOT = C:_Apps\Tools\Android\SDK • Java binary at: C:_Apps\Tools\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) • All Android licenses accepted.
[√] Chrome - develop for the web • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Professional 2019 16.11.2) • Visual Studio at C:_Apps\Tools\Visual Studio • Visual Studio Professional 2019 version 16.11.31624.102 • Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 2020.3) • Android Studio at C:_Apps\Tools\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
[√] Connected device (4 available) • Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.18363.1977] • Chrome (web) • chrome • web-javascript • Google Chrome 97.0.4692.71 • Edge (web) • edge • web-javascript • Microsoft Edge 97.0.1072.62
• No issues found!
Same issue here
Same issue here!
Maybe this will help someone ...
I had exactly same issue (IOS emulator only ) (Android works fine)
I managed to finally fix this on IOS emulator side...
Removed background permission for IOS in info.plist
and only left this one:
 <key>NSLocationWhenInUseUsageDescription</key>
<string>This app requires access to your location information to operate</string>
then finally cold run and i get the permissions dialog...select allow once or when using app and seems to be fine.
I experience the same bug although I'm requesting the same permission multiple times, e.g.
I defined a method which retrieves the location and checks if permission has been granted. I do this as I had crashes when requesting the location after running the permission request as a quick fix for now
Future<LocationData?> getLocation({LocationAccuracy accuracy = LocationAccuracy.high}) async {
    final granted = await ph.Permission.locationWhenInUse.isGranted;
    if (!granted) {
      final result = await ph.Permission.locationWhenInUse.request();
      Fimber.e('location has not been granted');
      return null;
    }
    final location = Location()..changeSettings(accuracy: accuracy);
    return location.getLocation();
}    
and in another place I try to update the location as fast as possible by running:
// Request one location precision after the other to reduce location update time
final lastKnownLocation = await getLocation(accuracy: LocationAccuracy.powerSave);
if (lastKnownLocation != null) {
   emit(OnLastKnownLocation(location: lastKnownLocation));
}
final normalLocation = await getLocation();
if (normalLocation != null) {
   emit(OnLocation(location: normalLocation));
}
final bestLocation = await getLocation(accuracy: LocationAccuracy.navigation);
if (bestLocation != null) {
   emit(OnLocation(location: bestLocation));
}
So somehow awaiting the permission response didn't really finish the request.
It might be not the best code but I guess it illustrates the problem quite well.
Same issue here!
@MagdyEl-Sayed
I've experienced the same issue and found a solution.
Did you override onRequestPermissionsResult in your MainActivity?
My fix is adding a fallback on a not managed requestCode like this snippet.
Without the fallback, the PermissionManager.onRequestPermissionsResult is never called and the plugin is not updated about the permission result.
override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        when (requestCode) {
            myRequestCode -> myFunction(myRequestCode)
            else -> super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
cc: @JDDV
Probably related to: https://github.com/Baseflow/flutter-permission-handler/issues/783 and https://github.com/Baseflow/flutter-permission-handler/issues/581
Same issue here.
flutter SDK 2.10.3 permission_handler: 10.2.0 or 11.0.1
device: Android 13
static Future<bool> locationGranted() async {
    bool isGranted = true;
    Map<Permission, PermissionStatus> statuses = await [
      Permission.location,
    ].request();
    statuses.forEach((key, permission) {
      if(permission.isDenied){
        isGranted = false;
      }
    });
    return isGranted;
  }
我也遇到了同样的问题,升级到11.0.1后作者解决了这个问题
Same issue here,and the problem was solved after upgrading to 11.0.1
Same issue here,and the problem was solved after upgrading to 11.0.1
Same issue.
I try to update permission_handler: ^11.1.0 , still alive this problem.
i was facing same in fcm..i double checked we are not requesting permission more than once but is still facing this issue..however we are not facing crashes so I have left it open.. The issue probably is in new flutter version and a migration is needed.. we will do it later but until then the app works just fine..
Any suggestions are most welcome..