Skip to content

Instantly share code, notes, and snippets.

@bharathraj-e
Created March 3, 2020 06:59
Show Gist options
  • Save bharathraj-e/4331a8c5c0a6d0a9cbcaa4d5ee2e3fe2 to your computer and use it in GitHub Desktop.
Save bharathraj-e/4331a8c5c0a6d0a9cbcaa4d5ee2e3fe2 to your computer and use it in GitHub Desktop.
import 'package:permission_handler/permission_handler.dart';
() async {
PermissionStatus p = await PermissionHandler()
.checkPermissionStatus(PermissionGroup.contacts);
if (p == PermissionStatus.disabled) {
// permission got already / success
return true;
}
Map<PermissionGroup, PermissionStatus> ps =
await PermissionHandler()
.requestPermissions([PermissionGroup.contacts]);
PermissionStatus q = ps[PermissionGroup.contacts];
if (q == PermissionStatus.granted) {
// permission granted
// do the stuff
return true;
}
if (q == PermissionStatus.denied) {
// permission denied
// don't do the stuff
return false;
}
if (q == PermissionStatus.neverAskAgain) {
// user restricted the permission
return false;
// below code to open current app settings if u wish ...
// await PermissionHandler().openAppSettings();
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment