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.
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 giving 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.