request_permission 1.0.1
request_permission: ^1.0.1 copied to clipboard
A flutter plugin for requesting android permissions.
Introduction #
Use his plugin to request permissions for the android part of your Flutter.
Setup #
Android
Add the permissions your app needs to the android/app/src/main/AndroidManifest.xml. Put the permissions in the tag not into the tag.
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
IOS
Currently this plugin only supports Android, if you want to you can contribute to it.
Usage #
After adding the permissions, you can request them in your Flutter app in the following way:
Obtain an instance
RequestPermission requestPermission = RequestPermission.instance;
Request the permissions
RaisedButton(
child: Text("request permissions"),
onPressed: () {
// 101 is the requestCode
requestPermission.requestMultipleAndroidPermissions(101, [
"android.permission.CAMERA",
"android.permission.CALL_PHONE"
]);
},
),
Or request just one permission:
RaisedButton(
child: Text("request camera permission"),
onPressed: () {
// 101 is the requestCode
requestPermission.requestAndroidPermission(27, "android.permission.CAMERA");
},
),
RaisedButton(
child: Text("request call_phone permission"),
onPressed: () {
// 101 is the requestCode
requestPermission.requestAndroidPermission(28, "android.permission.CALL_PHONE");
},
),
Listen to the user choice
requestPermission.results.listen((event) {
event.grantedPermissions.forEach((key, value) {
if (value) {
print("The permission <$value> has been granted!");
} else {
print("The permission <$value> has NOT been granted!");
}
});
});