Flutter-permission-handler: A request for permissions is already running - How stop request? - 5.0.0+hotfix.3

Created on 30 Mar 2020  Â·  16Comments  Â·  Source: Baseflow/flutter-permission-handler

Up to permission_handler 5.0.0+hotfix.2. Problem is still here.

Flutter 1.12.13+hotfix.8 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 0b8abb4724 (7 weeks ago) • 2020-02-11 11:44:36 -0800
Engine • revision e1e6ced81d
Tools • Dart 2.7.0

I have a simple app, where i ask permission storage.

Future<void> _attachFile() async {
    requestPermission(Permission.storage);

    bool storage = await isPermissionGranted(Permission.storage);

    if (!storage) {
      _showInSnackBar(Localization.of(context).translate('access_file'));
      return;
    }
    _attachedFile = await FilePicker.getFilePath(type: FileType.any);
    setState(() {});
  }

  Future<bool> isPermissionGranted(Permission permission) async {
    return await permission.isGranted;
  }

  Future<void> requestPermission(Permission permission) async {
    await permission.request();
  }

1 - Ask a permission, and say "no" (run Future _attachFile())
2- When ask again (run Future _attachFile()) i have a error
E/flutter (11118): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(PermissionHandler.PermissionManager, 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) - in log
And nothing happens in mobile

What i'am doing wrong?
Or in new version need work only with status? Like this:


var status = await Permission.camera.status;
if (status.isUndetermined) {
  // We didn't ask for permission yet.
}

You can can also directly ask the permission about its status.
if (await Permission.location.isRestricted) {
  The OS restricts access, for example because of parental controls.
}

PS Sorry for my English :-)

android bug

Most helpful comment

All 16 comments

I'm also having this same problem. Is there a certain way to determine if a permission request is already running?

If there is no such feature and it makes sense to you, I can try to add it.

I expect the following:
Access request
If the user replied "Deny" - the end of this request
Message output - access is needed for ...
A new access request, if the user decides to give permission - now this is possible only if you restart the application
How do I implement this?

PS Sorry for my English :-)

Was this page helpful?
0 / 5 - 0 ratings