以编程方式打开Flutter中的位置

问题描述 投票:0回答:2

我想以编程方式打开设备位置,而无需导航到设置屏幕。将会弹出一个询问位置的弹出窗口。单击确定按钮后,设备位置将打开。如何在Flutter中执行此操作?

flutter android-location
2个回答
0
投票
关于具有权限的弹出窗口,您必须为每个平台自行处理。对于定位包,您只需要在iOS上执行。您可以在软件包的说明中的“入门”和“用法”部分中详细了解它。

0
投票
@override void initState() { super.initState(); _checkPermissions(); } _checkPermissions() async { Location location = Location(); bool permission = await location.hasPermission() == PermissionStatus.GRANTED; if (!permission) { await location.requestPermission(); } }

现在使用此方法获取用户位置

Future<void> _getLocation(bool value) async {
 // show Loading on start
 // loading = true;
 // future Delayed if the user does not grant location second layer permission
 Future.delayed(Duration(seconds: 10), () {
  _error = 'Sorry, enable to get your location. \n Please try again';
});
 Location location = Location();
_locationData = await location.getLocation();
// After getting location do stuff here
}
© www.soinside.com 2019 - 2024. All rights reserved.