All Projects → Baseflow → Flutter Permission Handler

Baseflow / Flutter Permission Handler

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

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Flutter Permission Handler

Flutter Unity View Widget
Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
Stars: ✭ 961 (-16%)
Mutual labels:  flutter-plugin
Fluttermidicommand
A Flutter plugin to send and receive MIDI
Stars: ✭ 41 (-96.42%)
Mutual labels:  flutter-plugin
Flutterradioplayer
Flutter Radio Player, A Plugin to handle streaming audio without a hassle
Stars: ✭ 59 (-94.84%)
Mutual labels:  flutter-plugin
Flutter Contacts Plugin
Contact plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to read, create and update contacts from the address book.
Stars: ✭ 38 (-96.68%)
Mutual labels:  flutter-plugin
Matrixauth
High-performance lightweight distributed permission system. 高性能轻量级分布式权限系统。
Stars: ✭ 41 (-96.42%)
Mutual labels:  permission
Firebase auth ui
Flutter plugin for Firebase Auth UI. Supports popular auth providers by using native SDK for Android and iOS.
Stars: ✭ 44 (-96.15%)
Mutual labels:  flutter-plugin
Fluttertoast
Android Toast Plugin for Flutter
Stars: ✭ 957 (-16.35%)
Mutual labels:  flutter-plugin
Flutter appavailability
A Flutter plugin that allows you to check if an app is installed/enabled, launch an app and get the list of installed apps.
Stars: ✭ 63 (-94.49%)
Mutual labels:  flutter-plugin
Flutter wechat ble
ble 4.0 with wechat style api for flutter. flutter版微信api风格的低功耗蓝牙
Stars: ✭ 41 (-96.42%)
Mutual labels:  flutter-plugin
Onekeyperm
一键申请Android权限,不依赖任何业务Activity。小巧、简约、强悍
Stars: ✭ 56 (-95.1%)
Mutual labels:  permission
Flutter orientation
A Flutter plugin for device's orientation
Stars: ✭ 39 (-96.59%)
Mutual labels:  flutter-plugin
Vue Cli3.0 Vueadmin
基于vue-cli3.0+vue+elementUI+vuex+axios+权限管理的后台管理系统
Stars: ✭ 1,002 (-12.41%)
Mutual labels:  permission
Dlna Dart
A simple DLNA DMC library implemented by Dart.
Stars: ✭ 46 (-95.98%)
Mutual labels:  flutter-plugin
Leancloud flutter plugin
LeanCloud flutter plugin by Luna Gao
Stars: ✭ 34 (-97.03%)
Mutual labels:  flutter-plugin
Flutter svg
SVG parsing, rendering, and widget library for Flutter
Stars: ✭ 1,113 (-2.71%)
Mutual labels:  flutter-plugin
Flutter Woocommerce Api
WooCommerce API in Flutter, connect and start developing with the available endpoints like get products, create orders and more.
Stars: ✭ 31 (-97.29%)
Mutual labels:  flutter-plugin
Flutter branch sdk
Flutter Plugin for create deep link using Brach Metrics SDK. This plugin provides a cross-platform (iOS, Android).
Stars: ✭ 43 (-96.24%)
Mutual labels:  flutter-plugin
Stereo
A Flutter plugin for playing music on iOS and Android.
Stars: ✭ 66 (-94.23%)
Mutual labels:  flutter-plugin
Flutter native ads
Show AdMob Native Ads use PlatformView
Stars: ✭ 63 (-94.49%)
Mutual labels:  flutter-plugin
Math Metrix
This is Math-Puzzle game made in flutter and available on Playstore & AppStore
Stars: ✭ 48 (-95.8%)
Mutual labels:  flutter-plugin

pub package Build status style: effective dart

On most operating systems, permissions aren't just granted to apps at install time. Rather, developers have to ask the user for permissions while the app is running.

This plugin provides a cross-platform (iOS, Android) API to request permissions and check their status. You can also open the device's app settings so users can grant a permission.
On Android, you can show a rationale for requesting a permission.

Setup

While the permissions are being requested during runtime, you'll still need to tell the OS which permissions your app might potentially use. That requires adding permission configuration to Android- and iOS-specific files.

Android

Upgrade pre 1.12 Android projects

Since version 4.4.0 this plugin is implemented using the Flutter 1.12 Android plugin APIs. Unfortunately this means App developers also need to migrate their Apps to support the new Android infrastructure. You can do so by following the Upgrading pre 1.12 Android projects migration guide. Failing to do so might result in unexpected behaviour. Most common known error is the permission_handler not returning after calling the .request() method on a permission.

AndroidX

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 "gradle.properties" file:
android.useAndroidX=true
android.enableJetifier=true
  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: https://developer.android.com/jetpack/androidx/migrate).

Add permissions to your AndroidManifest.xml file. There's a debug, main and profile version which are chosen depending on how you start your app. In general, it's sufficient to add permission only to the main version. Here's an example AndroidManifest.xml with a complete list of all possible permissions.

iOS

Add permission to your Info.plist file. Here's an example Info.plist with a complete list of all possible permissions.

IMPORTANT: 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.

The permission_handler plugin use macros to control whether a permission is supported.

You can remove permissions you don't use:

  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: https://github.com/BaseflowIT/flutter-permission-handler/blob/develop/permission_handler/ios/Classes/PermissionHandlerEnums.h
          # e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
            '$(inherited)',
    
            ## dart: PermissionGroup.calendar
            # 'PERMISSION_EVENTS=0',
    
            ## dart: PermissionGroup.reminders
            # 'PERMISSION_REMINDERS=0',
    
            ## dart: PermissionGroup.contacts
            # 'PERMISSION_CONTACTS=0',
    
            ## dart: PermissionGroup.camera
            # 'PERMISSION_CAMERA=0',
    
            ## dart: PermissionGroup.microphone
            # 'PERMISSION_MICROPHONE=0',
    
            ## dart: PermissionGroup.speech
            # 'PERMISSION_SPEECH_RECOGNIZER=0',
    
            ## dart: PermissionGroup.photos
            # 'PERMISSION_PHOTOS=0',
    
            ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
            # 'PERMISSION_LOCATION=0',
           
            ## dart: PermissionGroup.notification
            # 'PERMISSION_NOTIFICATIONS=0',
    
            ## dart: PermissionGroup.mediaLibrary
            # 'PERMISSION_MEDIA_LIBRARY=0',
    
            ## dart: PermissionGroup.sensors
            # 'PERMISSION_SENSORS=0'
            
            ## dart: PermissionGroup.bluetooth
            # 'PERMISSION_BLUETOOTH=0'
          ]
    
        end
      end
    end
    
  2. Remove the # character in front of the permission you do not want to use. For example if you don't need access to the calendar make sure the code looks like this:
            ## dart: PermissionGroup.calendar
            'PERMISSION_EVENTS=0',
    
  3. 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: | Permission | Info.plist | Macro | | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ---------------------------- | | PermissionGroup.calendar | NSCalendarsUsageDescription | PERMISSION_EVENTS | | PermissionGroup.reminders | NSRemindersUsageDescription | PERMISSION_REMINDERS | | PermissionGroup.contacts | NSContactsUsageDescription | PERMISSION_CONTACTS | | PermissionGroup.camera | NSCameraUsageDescription | PERMISSION_CAMERA | | PermissionGroup.microphone | NSMicrophoneUsageDescription | PERMISSION_MICROPHONE | | PermissionGroup.speech | NSSpeechRecognitionUsageDescription | PERMISSION_SPEECH_RECOGNIZER | | PermissionGroup.photos | NSPhotoLibraryUsageDescription | PERMISSION_PHOTOS | | PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse | NSLocationUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription, NSLocationWhenInUseUsageDescription | PERMISSION_LOCATION | | PermissionGroup.notification | PermissionGroupNotification | PERMISSION_NOTIFICATIONS | | PermissionGroup.mediaLibrary | NSAppleMusicUsageDescription, kTCCServiceMediaLibrary | PERMISSION_MEDIA_LIBRARY | | PermissionGroup.sensors | NSMotionUsageDescription | PERMISSION_SENSORS | | PermissionGroup.bluetooth | NSBluetoothAlwaysUsageDescription, NSBluetoothPeripheralUsageDescription | PERMISSION_BLUETOOTH |
  4. Clean & Rebuild

How to use

There are a number of Permissions. You can get a Permission's status, which is either granted, denied, restricted or permanentlyDenied.

var status = await Permission.camera.status;
if (status.denied) {
  // We didn't ask for permission yet or the permission has been denied before but not permanently.
}

// You can can also directly ask the permission about its status.
if (await Permission.location.isRestricted) {
  // The OS restricts access, for example because of parental controls.
}

Call request() on a Permission to request it. If it has already been granted before, nothing happens.
request() returns the new status of the Permission.

if (await Permission.contacts.request().isGranted) {
  // Either the permission was already granted before or the user just granted it.
}

// You can request multiple permissions at once.
Map<Permission, PermissionStatus> statuses = await [
  Permission.location,
  Permission.storage,
].request();
print(statuses[Permission.location]);

Some permissions, for example location or acceleration sensor permissions, have an associated service, which can be enabled or disabled.

if (await Permission.locationWhenInUse.serviceStatus.isEnabled) {
  // Use location.
}

You can also open the app settings:

if (await Permission.speech.isPermanentlyDenied) {
  // The user opted to never again see the permission request dialog for this
  // app. The only way to change the permission's status now is to let the
  // user manually enable it in the system settings.
  openAppSettings();
}

On Android, you can show a rationale for using a permission:

bool isShown = await Permission.contacts.shouldShowRequestRationale;

Issues

Please file any issues, bugs or feature request as an issue on our GitHub page. Commercial support is available if you need help with integration with your app or services. You can contact us at [email protected].

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 [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].