Flutter:E/location_permissions:Geolocator插件中的结果对象为null [英] Flutter: E/location_permissions: result object is null in Geolocator plugin

查看:385
本文介绍了Flutter:E/location_permissions:Geolocator插件中的结果对象为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Flutter Project中使用Geolocator插件.我已经添加了Pubspecs.yaml文件,还添加了AndroidManifest文件中的权限.

I am using Geolocator plugin in Flutter Project. I have added it Pubspecs.yaml file also added the permission in AndroidManifest file.

Pubspecs.yaml

Pubspecs.yaml

dependencies:
  http: ^0.12.0
  flutter:
    sdk: flutter
  shimmer: ^1.0.1
  font_awesome_flutter: ^8.8.1
  geocoder: ^0.2.1
  geolocator: ^5.3.1

Android清单

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

我正在使用SDK 28-compileSdkVersion 28

I am using SDK 28 - compileSdkVersion 28

这是位置访问的代码.

String _locationMessage = ""; 

  void _getCurrentLocation() async {
    print('location');
    final position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
    print(position);

    setState(() {
      _locationMessage = "${position.latitude}, ${position.longitude}";
    });

  }

当我在按下的按钮上调用_getCurrentLocation()时.它显示了一个对话框,允许通过三个选项在App中访问位置.

When I call _getCurrentLocation() on Button Pressed. It is showing dialog box to allow location access in App with three option.

Allow all the time
Keep While-In-Use Access
Keep and Don't Ask Again

选择保留使用中的访问权限"后,它将在调试控制台中显示以下消息.

After selecting Keep While-In-Use Access it is giving below message in Debug console.

E/location_permissions( 7592): Flutter result object is null.

我在做什么错了?

另外,我想知道当我们尝试访问位置时是否会一直询问?还是只有一次?

Also, I want to know will it ask all the times when we try to access location or it will be one time?

如果我选择一直允许,则我的应用将停止响应.我的意思是,如果按下按钮,则什么也不会发生.另外,我需要从手机上卸载它,然后再次运行它,然后它开始提示您输入权限.

If I select Allow all the time then my app stop responding. I mean if press the button nothing happen. Also I need to uninstall it from phone and run it again then it start giving the prompt for permission.

我发现了一件奇怪的事情.如果定位服务已停止/未启用,那么我将得到null.如果我手动启用位置信息,那么它将开始为我提供位置信息.

One strange thing I found. If location service is stop/not enabled then I am getting null. If I manually enable location then it start giving me location.

推荐答案

我认为这与您使用的软件包(geolocator)有关, 当我关注youtube上的演讲

I think it has something to do with the package that you are using (geolocator), I've also faced the same issue, when I was following a lecture from youtube

所以我去了一些其他流行的软件包来获取位置 它的文档非常简单.

so I've gone for some other popular package to get location and it's documentation is very simple.

这篇关于Flutter:E/location_permissions:Geolocator插件中的结果对象为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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