1234567891011121314151617181920212223242526272829303132333435363738 |
- import 'dart:io';
-
- import 'package:permission_handler/permission_handler.dart';
-
- export 'package:permission_handler/permission_handler.dart';
-
- class PermissionUtils {
- static Future<bool> canPermission(Permission permission, [bool request = true]) async {
- if (permission == Permission.storage && Platform.isIOS) {
- return true;
- }
- if (permission == Permission.photos && Platform.isAndroid) {
- return true;
- }
- if (!await permission.status.isGranted) {
- if (request) {
- final PermissionStatus status = await permission.request();
- if (status.isDenied) {
- openAppSettings();
- }
- return status.isGranted;
- }
- return false;
- } else {
- return true;
- }
- }
-
- static Future<bool> canMultiplePermission(List<Permission> list, [bool request = true]) async {
- for (final Permission permission in list) {
- if (!await canPermission(permission, request)) {
- return false;
- }
- }
-
- return true;
- }
- }
|