Skip to content

fix🔨: permission_handler package updated permission fetch & request syntax #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,25 @@ class _HomePageState extends State<HomePage> {
}

Future<PermissionStatus> _getContactPermission() async {
PermissionStatus permission = await PermissionHandler()
.checkPermissionStatus(PermissionGroup.contacts);
if (permission != PermissionStatus.granted &&
permission != PermissionStatus.disabled) {
Map<PermissionGroup, PermissionStatus> permissionStatus =
await PermissionHandler()
.requestPermissions([PermissionGroup.contacts]);
return permissionStatus[PermissionGroup.contacts] ??
PermissionStatus.unknown;
PermissionStatus status = await Permission.contacts.status;

if (status != PermissionStatus.granted && status != PermissionStatus.permanentlyDenied) {
return await Permission.contacts.request();
} else {
return permission;
return status;
}
}

void _handleInvalidPermissions(PermissionStatus permissionStatus) {
if (permissionStatus == PermissionStatus.denied) {
throw PlatformException(
code: "PERMISSION_DENIED",
message: "Access to location data denied",
code: 'PERMISSION_DENIED',
message: 'Access to location data denied',
details: null);
} else if (permissionStatus == PermissionStatus.disabled) {
} else if (permissionStatus == PermissionStatus.restricted) {
throw PlatformException(
code: "PERMISSION_DISABLED",
message: "Location data is not available on device",
code: 'PERMISSION_DISABLED',
message: 'Location data is not available on device',
details: null);
}
}
Expand Down