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