DEV3 Technologies home

DEV3 Developer Forum

How do I request camera and location permissions in Flutter on both Android and iOS?

Flutter helpSolved0 views
dev3 ·

I use the permission_handler package. On Android the request dialog never shows and on iOS the app crashes when opening the camera. What platform configuration is required and how should the request flow look?

#flutter#permissions#ios#android

0

1 reply

dev3 · Accepted answer

1. Declare permissions on each platform

Android, android/app/src/main/AndroidManifest.xml (above <application>):

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

iOS, ios/Runner/Info.plist (a missing usage string crashes the app on access):

<key>NSCameraUsageDescription</key>
<string>We use the camera to scan barcodes.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We use your location to show nearby stores.</string>

2. iOS: enable the permission in the Podfile

permission_handler compiles only the permissions you enable. In ios/Podfile, inside post_install, set the macros, for example:

config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
  '$(inherited)',
  'PERMISSION_CAMERA=1',
  'PERMISSION_LOCATION=1',
]

Without this, requests return denied without ever showing a prompt. Check the package README for the macro names of your version.

3. Request flow in Dart

Future<bool> ensureCamera(BuildContext context) async {
  var status = await Permission.camera.status;
  if (status.isGranted) return true;

  status = await Permission.camera.request();
  if (status.isGranted) return true;

  if (status.isPermanentlyDenied) {
    // the OS will no longer show the dialog; send the user to settings
    await openAppSettings();
  }
  return false;
}

Good practice

  • Ask in context (when the user taps "Scan"), after a short explanation screen, not at app launch.
  • Handle denied, permanentlyDenied and (iOS) restricted separately.
  • On Android 13+ notifications need POST_NOTIFICATIONS; photo access has granular media permissions.
  • Test with a fresh install; permission state persists across hot restarts.

See a full pattern in the push permission flow snippet.

0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.