gpt4 book ai didi

flutter - 方法 'PermissionHandler' 没有为类定义

转载 作者:行者123 更新时间:2023-12-03 02:40:49 26 4
gpt4 key购买 nike

升级后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);
}

问题是什么?

最佳答案

那是因为来自 permission_handler: ^5.0.0作者 BaseFlow使我们使用起来更直观
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) .

关于flutter - 方法 'PermissionHandler' 没有为类定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61223071/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com