Skip to content

Instantly share code, notes, and snippets.

@Roaa94
Last active December 12, 2021 08:40
Show Gist options
  • Save Roaa94/1c09c374f3d8bb37b813c0b245f8d669 to your computer and use it in GitHub Desktop.
Save Roaa94/1c09c374f3d8bb37b813c0b245f8d669 to your computer and use it in GitHub Desktop.
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