permission_handler 4.2.0+hotfix.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 100

Flutter Permission handler Plugin #

pub package

A permissions plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.

BranchBuild Status
developBuild Status
masterBuild Status

Features #

  • Check if a permission is granted.
  • Request permission for a specific feature.
  • Open app settings so the user can enable a permission.
  • Show a rationale for requesting permission (Android).

Usage #

To use this plugin, add permission_handler as a dependency in your pubspec.yaml file. For example:

  permission_handler: '^4.2.0+hotfix.2'

NOTE: As of version 3.1.0 the permission_handler plugin switched to the AndroidX version of the Android Support Libraries. This means you need to make sure your Android project is also upgraded to support AndroidX. Detailed instructions can be found here.

The TL;DR version is:

  1. Add the following to your "" file:
  1. Make sure you set the compileSdkVersion in your "android/app/build.gradle" file to 28:
android {
 compileSdkVersion 28

  1. Make sure you replace all the android. dependencies to their AndroidX counterparts (a full list can be found here:

Android and iOS specific permissions #

For this plugin to work you will have to add permission configuration to your AndroidManifest.xml (Android) and Info.plist (iOS) files. This will tell the platform which hardware or software features your app needs. Complete lists of these permission options can be found in our example app here:

  • AndroidManifest.xml (note that there is a debug, main and profile version which are used depending on how you start your App. In general it is sufficient to add permissions only to the main version);
  • Info.plist

IMPORTANT: On iOS you will have to include all permission options when you want to submit your App. This is because the permission_handler plugin touches all different SDKs and because the static code analyser (run by Apple upon App submission) detects this and will assert if it cannot find a matching permission option in the Info.plist. More information about this can be found here.

On iOS, the permission_handler plugin use macros to control whether a permission is supported.

By default, all the permissions listed here are supported.

You can remove permissions you don't use by:

  1. Add the following to your Podfile file:

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          ... # Here are some configurations automatically generated by flutter
          # You can remove unused permissions here
          # for more infomation:
          # e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
            ## dart: PermissionGroup.calendar
            # 'PERMISSION_EVENTS=0',
            ## dart: PermissionGroup.reminders
            # 'PERMISSION_REMINDERS=0',
            ## dart: PermissionGroup.contacts
            # 'PERMISSION_CONTACTS=0',
            ## dart:
            # 'PERMISSION_CAMERA=0',
            ## dart: PermissionGroup.microphone
            # 'PERMISSION_MICROPHONE=0',
            ## dart: PermissionGroup.speech
            ## dart:
            # 'PERMISSION_PHOTOS=0',
            ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
            # 'PERMISSION_LOCATION=0',
            ## dart: PermissionGroup.notification
            ## dart: PermissionGroup.mediaLibrary
            ## dart: PermissionGroup.sensors
            # 'PERMISSION_SENSORS=0'
  2. Delete the corresponding permission description in Info.plist

    e.g. when you don't need camera permission, just delete 'NSCameraUsageDescription'

    The following lists the relationship between Permission and The key of Info.plist:

    PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUseNSLocationUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription, NSLocationWhenInUseUsageDescriptionPERMISSION_LOCATION
    PermissionGroup.mediaLibraryNSAppleMusicUsageDescription, kTCCServiceMediaLibraryPERMISSION_MEDIA_LIBRARY
  3. Clean & Rebuild


Requesting permission #

import 'package:permission_handler/permission_handler.dart';

Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([PermissionGroup.contacts]);

Checking permission #

import 'package:permission_handler/permission_handler.dart';

PermissionStatus permission = await PermissionHandler().checkPermissionStatus(PermissionGroup.contacts);

Checking service status #

import 'package:permission_handler/permission_handler.dart';

ServiceStatus serviceStatus = await PermissionHandler().checkServiceStatus(PermissionGroup.location);

Checking the service status only makes sense for the PermissionGroup.location on Android and the PermissionGroup.location, PermissionGroup.locationWhenInUser, PermissionGroup.locationAlways or PermissionGroup.sensors on iOS. All other permission groups are not backed by a separate service and will always return ServiceStatus.notApplicable.

Open app settings #

import 'package:permission_handler/permission_handler.dart';

bool isOpened = await PermissionHandler().openAppSettings();

Show a rationale for requesting permission (Android only) #

import 'package:permission_handler/permission_handler.dart';

bool isShown = await PermissionHandler().shouldShowRequestPermissionRationale(PermissionGroup.contacts);

This will always return false on iOS.

List of available permissions #

Defines the permission groups for which permissions can be checked or requested.

enum PermissionGroup {
  /// The unknown permission only used for return type, never requested

  /// Android: Calendar
  /// iOS: Calendar (Events)

  /// Android: Camera
  /// iOS: Photos (Camera Roll and Camera)

  /// Android: Contacts
  /// iOS: AddressBook

  /// Android: Fine and Coarse Location
  /// iOS: CoreLocation (Always and WhenInUse)

  /// Android: Microphone
  /// iOS: Microphone

  /// Android: Phone
  /// iOS: Nothing

  /// Android: Nothing
  /// iOS: Photos

  /// Android: Nothing
  /// iOS: Reminders

  /// Android: Body Sensors
  /// iOS: CoreMotion

  /// Android: Sms
  /// iOS: Nothing

  /// Android: External Storage
  /// iOS: Nothing

  /// Android: Microphone
  /// iOS: Speech

  /// Android: Fine and Coarse Location
  /// iOS: CoreLocation - Always

  /// Android: Fine and Coarse Location
  /// iOS: CoreLocation - WhenInUse

  /// Android: None
  /// iOS: MPMediaLibrary

  /// Android: Check notification enable
  /// iOS: Check and request notification permission

Status of the permission #

Defines the state of a permission group

enum PermissionStatus {
  /// Permission to access the requested feature is denied by the user.

  /// Permissions to access the feature is granted by the user but the feature is disabled.

  /// Permission to access the requested feature is granted by the user.

  /// The user granted restricted access to the requested feature (only on iOS).

  /// Permission is in an unknown state
  /// Permission to access the requested feature is denied by the user and never show selected (only on Android).

Overview of possible service statuses #

Defines the state of the backing service for the supplied permission group

/// Defines the state of a service related to the permission group
enum ServiceStatus {
  /// The unknown service status indicates the state of the service could not be determined.

  /// There is no service for the supplied permission group.

  /// The service for the supplied permission group is disabled.

  /// The service for the supplied permission group is enabled.

Issues #

Please file any issues, bugs or feature request as an issue on our GitHub page.

Want to contribute #

If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our contribution guide and send us your pull request.

Author #

This Permission handler plugin for Flutter is developed by Baseflow. You can contact us at

4.2.0+hotfix.2 #

  • Android: Fixes a bug where permissions are reported as neverAskAgain incorrectly after calling requestPermissions method.

4.2.0+hotfix.1 #

  • Android: Fixes a bug where permissions are reported as neverAskAgain incorrectly.

4.2.0 #

  • Android: Methods checkPermissionStatus and requestPermissions now support addition neverAskAgain status.

4.1.0 #

  • iOS: Added option to exclude permissions logic using macros. This allows developers to submit their app to the AppStore without having to include all permissions in their Info.plist;
  • Android: Support ANSWER_PHONE_CALLS permission for API 26 and higher;
  • Android: Support ACCESS_MEDIA_LOCATION permission for API 26 and higher;
  • Android: Synchronized Gradle version with Flutter stable (1.12.13+hotfix.5).

4.0.0 #

  • iOS: Added support for requesting permissions on the DOCUMENTS and DOWNLOADS folder (thanks to @phranck);
  • Androis: Fix the PROCESS_OUTGOING_CALLS permissions which have been deprecated in API 29.

3.3.0 #

  • Android: Add support for requesting the background location permission within the locationAlways group.
  • Android: Update AGP, Gradle and AndroidX dependencies

3.2.2 #

  • Fixed problem with dependency on specific version of gradle wrapper on Android.

3.2.1+1 #

  • Reverted the update of the 'meta' plugin since Flutter SDK depends on version 1.1.6

3.2.1 #

  • Updated dependecy on 'meta' to latest version.

3.2.0 #

  • Add support for Androids' "ignore battery optimizations" permission;
  • Improve error logging;
  • Documented support for AndroidX.

3.1.0 #

  • Support service status inquiry for phone permission on iOS & Android.

3.0.2 #

  • Fixed bug when rapidly requesting permissions (#23);
  • Rename Enums.h to PermissionHandlerEnums.h to prevent conflicts with geolocator (#104);
  • Update the Android permission request code to prevent conflicts with geolocator (#111);
  • Update Gradle infrastructure.

3.0.1 #

  • Mark the Swift pod as static

3.0.0 #

  • Converted the iOS version from Swift to Objective-C, reducing the size of the final binary considerably.

2.2.0 #

  • Added new method checkServiceStatus to allow users to check if the location services (on Android and iOS) and motion services (iOS only) are enabled;
  • When checking permission status (using checkPermissionStatus) return PermissionStatus.disabled when permissions are granted or denied and the location services (on Android and iOS) or the motion services (iOS only) are disabled.

2.1.3 #

  • Fixed bug on iOS where result of the openAppSettings call always returned false;
  • Upgrade Android plugin to support AndroidX and latest Gradle and Kotlin versions;
  • Added Swift version number to the Podfile of the plugin;
  • Updated flutter static analyzes to conform to latest recommendations.

2.1.2 #

  • Make sure the Permission Handler compiles with latest iOS SDK

2.1.1 #

  • Update to the latest version of Swift (4.2);
  • Make sure that the correct Swift version is set in the Podfile of consuming Apps;
  • Updated configuration for statis code analyses, so it complies with the Flutter recommendations.

2.1.0 #

  • Added Android support to check if location services are enabled. If location services are not running the permission check returns PermissionStatus.DISABLED.

2.0.1 #

  • Fix bug with dependency on library
  • Update used Kotlin and Gradle versions

2.0.0 #

  • Make methods non static so users can create an instance or override

1.0.1 #

  • Converted the plugin into a library so that developers don't have to import additional files;
  • Updated the to fix example code.

1.0.0 #

  • Initial release.


permission_handler_example #

Demonstrates how to use the permission_handler plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  permission_handler: ^4.2.0+hotfix.2

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:permission_handler/permission_handler.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
meta ^1.1.6 1.1.8
Transitive dependencies
collection 1.14.11 1.14.12
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
pedantic ^1.7.0