skip to Main Content

I recently published a Flutter app on Google Play. It worked perfectly while developing, but the version published on Google Play never asks for location permissions. It marks location permission as permanentlyDenied automatically.

This is the function that should trigger the location permission request:

  _getUserLocation() {
    if(context.read<UserLocationCubit>().state == null) {
      Permission.locationWhenInUse.request().then((PermissionStatus permissionStatus) {
        // If permission granted (permanently or not)...
        if(permissionStatus != PermissionStatus.permanentlyDenied && permissionStatus != PermissionStatus.denied) {
          setState(() {
            locationDenied = false;
          });
          Geolocator.getCurrentPosition(
            locationSettings: const LocationSettings(
              accuracy: LocationAccuracy.high,
            ),
          ).then((Position position) {
            LatLng newPosition = LatLng(position.latitude, position.longitude);
            context.read<UserLocationCubit>().set(
              location: newPosition,
            );
            setState(() {
              userLocation = newPosition;
            });
          });
        } else { // If permission denied (permanently or not)...
          setState(() {
            locationDenied = true;
          });
        }
      });
    } else {
      /* More stuff */
    }
  }

locationDenied is a nullable bool? but right after installing my app from Google Play, this function is called and I see the screen as expected when locationDenied is true, and it can only be set as true by this function. Conclusion: my app is automatically denying location permissions by default, not even asking.

When I go to my app settings (right after that) I see the following:
Location permission not allowed

My pupspec.yaml is the following:

name: he_name_of_my_app
description: "The_name_of_my_app"
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.9+9

environment:
  sdk: '>=3.4.0-268.0.dev <4.0.0'

dependencies:
  flutter:
    sdk: flutter

  app_links: ^6.2.1
  bloc: ^8.1.4
  carousel_slider: ^5.0.0
  cupertino_icons: ^1.0.6
  flutter_bloc: ^8.1.6
  flutter_secure_storage: ^9.2.2
  flutter_svg: ^2.0.10+1
  geolocator: ^13.0.1
  get: ^4.6.6
  google_fonts: ^6.2.1
  google_maps_flutter: ^2.9.0
  http: ^1.2.2
  image_picker: ^1.1.2
  mobile_scanner: ^5.2.1
  permission_handler: ^11.3.1
  qr_flutter: ^4.1.0
  share_plus: ^10.0.2
  # syncfusion_flutter_charts: ^26.2.10
  syncfusion_flutter_pdfviewer: ^26.2.10
  url_launcher: ^6.3.0
  webview_flutter: ^4.9.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^3.0.0

flutter:
  uses-material-design: true

  assets:
    - assets/images/
    - assets/documents/terms_and_conditions.pdf

After searching plenty of sites, none got me to the solution. This is what I tried:

  • Of course, I completely deleted the app and flutter clean

  • I checked my AndroidManifest, looking like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:label="The_name_of_my_app"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="true"
        >
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="standard"
            android:taskAffinity=""
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <meta-data
            android:name="flutter_deeplinking_enabled"
            android:value="true" />
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="my_api_key" />
    </application>
    <queries>
        <intent>
            <action android:name="android.intent.action.PROCESS_TEXT"/>
            <data android:mimeType="text/plain"/>
        </intent>
    </queries>
</manifest>
  • I changed my request from Permission.location to Permission.locationWhenInUse so that Google doesn’t think that I want to get any other kind of location like background location or finer location, which I didn’t add on my AndroidManifest. The app neither work with Permission.location

  • I made sure that my AppBundle is on release mode.

  • I tried to use camera permissions on the Google Play version to make sure the problem is only related on the location one. The camera permission request popped up normally.

  • I tried downloading the Google Play version on other phones with different Android versions. Same issue on all of them.

Any help would be extremely appreciated, considering that my app is already on air! Thank you in advance.

2

Answers


  1. Working on debug but not on production it can be due to multiple factors.

    1. Try to add
      inside application tag.
    2. Use proguard
    3. Check it locally by flutter run –release
      Hope it will help
    Login or Signup to reply.
  2. Maybe answers here can help, if you din’t check it already:
    https://github.com/Baseflow/flutter-permission-handler/issues/406

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search