问题是google_maps_flutter软件包需要访问您位置的权限,但该软件包没有本机代码来请求该权限。
因此,您需要编写本机代码或仅安装另一个能够获得该许可权的软件包。
安装此程序:https :
//pub.dartlang.org/packages/location
然后:
getLocationPermission() async { final Location location = new Location(); try { location.requestPermission(); //to lunch location permission popup } on PlatformException catch (e) { if (e.pre == 'PERMISSION_DENIED') { print('Permission denied'); } } }或者,如果您想要更坚实的代码,这是我用于某些项目的代码(带有位置包):
//Show some loading indicator depends on this boolean variablebool askingPermission = false;@override void initState() { this.getLocationPermission(); super.initState(); } Future<bool> getLocationPermission() async { setState(() { this.askingPermission = true; }); bool result; final Location location = Location(); try { if (await location.hasPermission()) result = true; else { result = await location.requestPermission(); } print('getLocationPermission: ' '${result ? 'Access Allowed' : 'Access Denied'}'); } catch (log, trace) { result = false; print('getLocationPermission/log: $log'); print('getLocationPermission/trace: $trace'); } finally { setState(() { this.askingPermission = false; }); } return result; }


