How to handle users permission with flutter

Oliver Felix
2 min readJun 6, 2021
permission_handler package

Handle users permission with flutter is very simple.

Lest do it

1. Add this package to your pubspec.yaml file

permission_handler: ^4.2.0+hotfix.3

after adding this you need to run pub get

2 . Now in your Dart code, you can use:

import 'package:permission_handler/permission_handler.dart';

3. Add This function for ask permission

_askPermission() async {
if (Platform.isIOS) {
/*Map<PermissionGroup, PermissionStatus> permissions =
*/
await PermissionHandler().requestPermissions([PermissionGroup.photos]);
} else {
/* PermissionStatus permission = */ await PermissionHandler()
.checkPermissionStatus(PermissionGroup.storage);
}
}

hint : in this case you need to change the PermissionGroup type according to your needs.

4. Call to that Function in initstate()

_askPermission();

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

Add the permissions to Manifest.xml file. this need to import after the application closing tag

<uses-permission android:name=”android.permission.INTERNET” />
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”/>
<uses-permission android:name=”android.permission.READ_EXTERNAL_STORAGE” />
<uses-permission android:name=”android.permission.SET_WALLPAPER” />

Note: this permission types need to change with your needs

IOS:

Add permission to your Info.plist file

All are done.. Congratulations…!

Additional reading

I am using permission_handler package. But I have faced problem with installing the new version of that.

so install it like this

permission_handler: ^4.2.0+hotfix.3

--

--