PermissionHandler升级到最新版本(5.0.0)之后。找不到PermissionHandler(),也The name 'PermissionGroup' isn't a type so it can't be used as a type argument.

这是一个代码片段:

  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);
  }

问题是什么?

最佳答案

那是因为作者BaseFlowpermission_handler: ^5.0.0中使我们使用起来更加直观
this issue ticker (#230)所问。

您的代码段需要进行如下更改:

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

因此,现在这些映射如下:
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

在此处阅读更多信息:this issue ticker (#230)

10-07 17:04