Last active
December 12, 2021 08:40
-
-
Save Roaa94/1c09c374f3d8bb37b813c0b245f8d669 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_tutorials/common/ui/widgets/app_alert_dialog.dart'; | |
import 'package:flutter_tutorials/file-upload-service-tutorial/data/services/permission/permission_service.dart'; | |
import 'package:permission_handler/permission_handler.dart'; | |
class PermissionHandlerPermissionService implements PermissionService { | |
@override | |
Future<PermissionStatus> requestCameraPermission() async { | |
return await Permission.camera.request(); | |
} | |
@override | |
Future<PermissionStatus> requestPhotosPermission() async { | |
return await Permission.photos.request(); | |
} | |
@override | |
Future<bool> handleCameraPermission(BuildContext context) async { | |
PermissionStatus cameraPermissionStatus = await requestCameraPermission(); | |
if (cameraPermissionStatus != PermissionStatus.granted) { | |
print('π° π° π° π° π° π° Permission to camera was not granted! π° π° π° π° π° π°'); | |
await showDialog( | |
context: context, | |
builder: (_context) => AppAlertDialog( | |
onConfirm: () => openAppSettings(), | |
title: 'Camera Permission', | |
subtitle: 'Camera permission should Be granted to use this feature, would you like to go to app settings to give camera permission?', | |
), | |
); | |
return false; | |
} | |
return true; | |
} | |
@override | |
Future<bool> handlePhotosPermission(BuildContext context) async { | |
PermissionStatus photosPermissionStatus = await requestPhotosPermission(); | |
if (photosPermissionStatus != PermissionStatus.granted) { | |
print('π° π° π° π° π° π° Permission to photos not granted! π° π° π° π° π° π°'); | |
await showDialog( | |
context: context, | |
builder: (_context) => AppAlertDialog( | |
onConfirm: () => openAppSettings(), | |
title: 'Photos Permission', | |
subtitle: 'Photos permission should Be granted to use this feature, would you like to go to app settings to give photos permission?', | |
), | |
); | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment