Keine Beschreibung

permission_utils.dart 1004B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import 'dart:io';
  2. import 'package:permission_handler/permission_handler.dart';
  3. export 'package:permission_handler/permission_handler.dart';
  4. class PermissionUtils {
  5. static Future<bool> canPermission(Permission permission, [bool request = true]) async {
  6. if (permission == Permission.storage && Platform.isIOS) {
  7. return true;
  8. }
  9. if (permission == Permission.photos && Platform.isAndroid) {
  10. return true;
  11. }
  12. if (!await permission.status.isGranted) {
  13. if (request) {
  14. final PermissionStatus status = await permission.request();
  15. if (status.isDenied) {
  16. openAppSettings();
  17. }
  18. return status.isGranted;
  19. }
  20. return false;
  21. } else {
  22. return true;
  23. }
  24. }
  25. static Future<bool> canMultiplePermission(List<Permission> list, [bool request = true]) async {
  26. for (final Permission permission in list) {
  27. if (!await canPermission(permission, request)) {
  28. return false;
  29. }
  30. }
  31. return true;
  32. }
  33. }