Flutter上用于位置设置的本机对话框 [英] Native Dialog for location setting on Flutter

查看:214
本文介绍了Flutter上用于位置设置的本机对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以实现位置对话框"设置,例如下图所示,当应用需要GPS定位但找不到GPS时会触发该对话框.点击确定将立即打开系统GPS.对于用户而言,这似乎比将他们带到位置并手动打开更方便. 可以在Flutter中实现这样的事情吗?

Is there a way to implement a Dialog for Location setting like the image below which gets triggered when app requires GPS location and doesn't find. Hitting OK will right away turn on the system GPS. This seems more convenient for users instead of taking them to location and manually turn on. Is it possible to implement such thing in Flutter?

对话框的展开视图:

推荐答案

在此处回答,请授予Rajesh.通过插件,您可以添加此本机对话框以进行快速位置设置.

Credits to Rajesh, as answered here. The plugin lets you add this native dialog for a quick location setting.

实现非常简单:

import 'package:location/location.dart';

var location = Location();

Future _checkGps() async {
if(!await location.serviceEnabled()){
   location.requestService();
  }
}

@override
void initState() {
  super.initState();
  _checkGps();
}

这篇关于Flutter上用于位置设置的本机对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆