Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method 'PermissionHandler' isn't defined for the class

Tags:

flutter

dart

After upgrading PermissionHandler to latest (5.0.0). The PermissionHandler() not found and also The name 'PermissionGroup' isn't a type so it can't be used as a type argument..

Here is a code snippet:

  PermissionStatus permission = await PermissionHandler().checkPermissionStatus(PermissionGroup.storage);
  if (permission != PermissionStatus.granted && permission != PermissionStatus.neverAskAgain) {
    Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([PermissionGroup.storage]);
    if (permissions.containsValue(2))
      fileDownload(context, finalUrl);
  } 

What is the problem?

like image 591
Blasanka Avatar asked Apr 15 '20 07:04

Blasanka


2 Answers

That because from permission_handler: ^5.0.0 the author BaseFlow made it more intuitive for us to use as asked in this issue ticker (#230).

Your code snippet need to change like below:

  if (await Permission.storage.request().isGranted) {
      fileDownload(context, finalUrl);
  }

So now those mapped like this:

old way                                                 new way
-------                                                 -------

await PermissionHandler()
   .checkPermissionStatus(PermissionGroup.camera)       await PermissionGroup.camera.status

await PermissionHandler().requestPermissions(
   [PermissionGroup.camera]))[PermissionGroup.camera]   await PermissionGroup.camera.request()

await PermissionHandler().requestPermissions(
   [PermissionGroup.camera, PermissionGroup.storage]))  await [PermissionGroup.camera,                                   PermissionGroup.storage].request()

await PermissionHandler().checkServiceStatus
   (PermissionGroup.location)                           await Permission.location.serviceStatus.isEnabled

Read more here: this issue ticker (#230).

like image 129
Blasanka Avatar answered Dec 23 '22 16:12

Blasanka


Use permission_handler: ^3.0.0 ,it Worked for me

like image 20
chethanv77777 Avatar answered Dec 23 '22 15:12

chethanv77777