-
Notifications
You must be signed in to change notification settings - Fork 6
/
permission_handler_permission_service.dart
54 lines (48 loc) · 2.01 KB
/
permission_handler_permission_service.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import 'package:flutter/material.dart';
import 'package:flutter_tutorials/common/ui/widgets/app_alert_dialog.dart';
import 'package:flutter_tutorials/avatar-uploader-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;
}
}