A flutter plugin for handling permissions on Android/iOS in a very simple way.
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.
First add this package in your pubspec.yaml
file:
dependencies:
flutter:
sdk: flutter
super_easy_permissions: any
Make sure to GET all the pub packages after saving this file.
Add the required permissions in your AndroidManifest.xml
file:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
In this case, I have added camera permission (which also require adding hardware feature). Your's case may be different. For example, You may require storage permissions.
NOTE: If you need to add storage permissions in AndroidManifest.xml
, make sure to add the following line in manifest file:
<application
android:requestLegacyExternalStorage="true"
...
For a list of all permissions, visit Google Developers
site.
Add required permissions in Info.plist
file:
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) camera description.</string>
In this case, I have added camera permission. Your need may be different.
For a list of all permissions, visit Apple Developers
site.
Import the library in your dart file:
import 'package:super_easy_permissions/super_easy_permissions.dart';
Finally, use the package
bool result = await SuperEasyPermissions.isGranted(Permissions.camera);
if (result) {
// Permission is granted, do something
}
bool result = await SuperEasyPermissions.askPermission(Permissions.camera);
if (result) {
// Permission is granted, do something
} else {
// Permission denied, do something else
}
bool result = await SuperEasyPermissions.isDenied(Permissions.camera);
if (result) {
// Permission is denied, do something
}
Permissions.accessMediaLocation // for android only
Permissions.activityRecognition // for android only
Permissions.bluetooth
Permissions.calendar
Permissions.camera
Permissions.contacts
Permissions.ignoreBatteryOptimizations // for ios only
Permissions.location
Permissions.locationAlways
Permissions.locationWhenInUse
Permissions.mediaLibrary // for ios only
Permissions.microphone
Permissions.notification
Permissions.phone // for android only
Permissions.photos // for ios only
Permissions.photosAddOnly // for ios only
Permissions.reminders // for ios only
Permissions.sensors
Permissions.sms // for android only
Permissions.speech
Permissions.storage
Don't hesitate to email any issues or feature at [email protected].
Please support me via Donation. Your donation seriously motivates me to develop more useful packages like this.
This Permission plugin for Flutter is developed by Rituraj Shakti. You can contact me at [email protected]