You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter Web中location.hasPermission()抛出TypeError问题求助

Flutter Web平台location包hasPermission()方法抛出类型错误

location包的相关方法在iOS和Android平台运行正常,但在Web平台调用location.hasPermission()时,包内部抛出类型错误。

我的代码:

_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
  _serviceEnabled = await location.requestService();
  if (!_serviceEnabled) {
    StackTrace.current
        .printWithInfo('No User Location Available: Services Not Enabled!');
    streamController.add(_initialFocusLocation);
    return;
  }
}

// try {
_permissionGranted = await location.hasPermission();
if (_permissionGranted == PermissionStatus.denied ||
    _permissionGranted == PermissionStatus.deniedForever) {
  _permissionGranted = await location.requestPermission();
  if (_permissionGranted != PermissionStatus.granted ||
      _permissionGranted != PermissionStatus.grantedLimited) {
    StackTrace.current
        .printWithInfo('No User Location Available: Permission Not Granted!');
    streamController.add(_initialFocusLocation);
    return;
  }
}

错误信息:

TypeError: Failed to execute 'query' on 'Permissions': Failed to read the 'name' property from 'PermissionDescriptor': Required member is undefined.
packages/location_web/location_web.dart 60:15                               hasPermission

使用的包及版本:

  • location: 6.0.2
  • flutter: 3.22.2
  • dart: 3.4.3

请问有没有人成功在Web平台实现该功能?

内容的提问来源于stack exchange,提问作者Aaron Kennedy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 07:44:52