Cannot ask for location permission on flutter
use the following package in flutter to get location permission :Location permission package
First add the package to pubspec.yaml file after (sdk:flutter) line:
location_permissions: ^2.0.5
Second: in the main.dart file add the following lines to the beginning :
import 'package:location_permissions/location_permissions.dart';
PermissionStatus permission = await LocationPermissions().requestPermissions();
GusHill
Updated on December 10, 2022Comments
-
GusHill over 1 year
I'm creating a test application in flutter using google_maps_flutter and geolocator for tracking a phone's location. The problem is that when I ask for location permission no dialog is shown.
I've already tried 2 other packages, simple_permissions and permission, which gave me gradle errors, now I'm trying with permission_handler, but it can't find the permission in manifest
how I try to ask for permission
await PermissionHandler().requestPermission([PermissionGroup.locationAlways]);
My android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.example.geolocation"> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <application ... </manifest>
my android/app/build.gradle
def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion 28 lintOptions { disable 'InvalidPackage' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.geolocalization" minSdkVersion 23 targetSdkVersion 28 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } } } flutter { source '../..' } dependencies { compile 'com.google.android.gms:play-services-maps:16.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.1.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.1.1' }
what is prompted in my console
D/permissions_handler(20397): No permissions found in manifest for: $permission I/flutter (20397): decodePermissionRequestResult called with: value:[{4: 4}]
-
Rob C about 5 yearsYou might need
<uses-feature android:name="android.hardware.location.gps" />
in your manifest... -
Keerti Purswani about 5 yearsDuplicate of stackoverflow.com/questions/53787755/…
-
Stefano Miceli about 5 years@Keerti Purswani No, is not a Duplicate. In your question you are using location plugin. Here the plugin is geolocator. Probably the error is the same, but also in your question there isn't checked answer. So, don't stop people from possible answers with duplicate. Thanks
-
Stefano Miceli about 5 yearsIn any case @GusHill have you tried to add <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-feature android:name="android.hardware.location.gps" /> in your manifest and then Flutter clean and rebuild ?
-