Flutter使用location 4.4.0包遇Location构造及granted成员找不到错误
解决location包4.4.0的两个错误:找不到'Location'方法和'granted'成员
location包4.x版本对核心API做了重构,你遇到的两个错误都是API变更导致的,修正方案如下:
修正实例化代码:原
Location类已被替换为LocationManager,代码改成:LOC.LocationManager locationManager = LOC.LocationManager();修正权限判断代码:权限状态枚举值
granted已更名为authorized,判断逻辑改成:if (_permissionGranted != LOC.PermissionStatus.authorized) { return; }
另外,4.x版本还调整了权限请求相关的API,比如原requestPermission()方法已改为requestAuthorization(),如果后续涉及权限请求逻辑,也需要同步调整对应代码。
内容的提问来源于stack exchange,提问作者Ahmed Wagdi
相关产品推荐
相关产品推荐

