I have created below method to check the location permission status in my flutter application:
Future<void> checkLocationPermission(
BuildContext context, UserCredential userCredential) async {
locationPermissionStatus = await permission_status.Permission.location
.request()
.then((value) async {
if (locationPermissionStatus.isGranted) {
displayToast("granted");
await getCurrentLocation(context, userCredential);
} else {
displayToast("not granted");
}
return locationPermissionStatus;
});
}
Where, PermissionStatus is declared as below:
permission_status.PermissionStatus locationPermissionStatus =
permission_status.PermissionStatus.denied;
Imports as below:
import 'package:location/location.dart';
import 'package:permission_handler/permission_handler.dart' as permission_status;
Used below plugins:
permission_handler: ^10.2.0
location: ^4.4.0
But In App, When Location Permission pops up, I am tapping on option "While Using the App"
But I am always getting the toast display as "not granted"
What might be the issue? Thanks in Advance.
EDIT:
Already added below permissions for Android:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
</manifest>
3
Answers
You have to add permission in manifest.
Like this : https://i.stack.imgur.com/PgdNF.png
Also permission status is not working correctly for only location permission so you have check and request permission using location package and it will works fine.
I Hope this things are solve your issue.
Adding to the @Romil Mavani answer, you first have to add permissions in
AndroidManifest
:But it also seems that you are using
async/await
with the combination ofthen
which is very error-prone. You should either use one or the other.If you’re using a Windows Emulator
I’ve faced the same issue before, but when I opened the
application setting
of my mobile’s emulator to confirm, the location permission was not granted (off).So, I
granted it manually
from the app settings.This solution works for me.