Flutter: E/location_permissions: result object is null in Geolocator plugin

僤鯓⒐⒋嵵緔 提交于 2020-04-30 06:57:07

问题


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

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 Manifest

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

I am using SDK 28 - compileSdkVersion 28

Here is the code for location access.

String _locationMessage = ""; 

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

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

  }

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.

Please advise what am i doing wrong.

Also i want to know will it ask all the times when we try to access location or it will be one time.

Edit 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 givng the prompt for permission.

Edit 2

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.

来源:https://stackoverflow.com/questions/61472420/flutter-e-location-permissions-result-object-is-null-in-geolocator-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!