Skip to content

Commit 97aad86

Browse files
committed
updated permission request functionality
1 parent 604c4e2 commit 97aad86

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

lib/app/modules/permission/controllers/permission_controller.dart

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import 'package:flutter/material.dart';
22
import 'package:get/get.dart';
33
import 'package:permission_handler/permission_handler.dart';
4+
import 'package:taskwarrior/app/utils/permissions/permissions_manager.dart';
45

56
class PermissionController extends GetxController {
67
final RxBool isStorageGranted = false.obs;
78
final RxBool isNotificationGranted = false.obs;
9+
final RxBool isExteternalStorageGranted = false.obs;
810
final RxBool isLoading = false.obs;
911

1012
@override
@@ -18,6 +20,8 @@ class PermissionController extends GetxController {
1820
isStorageGranted.value = await Permission.storage.status.isGranted;
1921
isNotificationGranted.value =
2022
await Permission.notification.status.isGranted;
23+
isExteternalStorageGranted.value =
24+
await Permission.manageExternalStorage.status.isGranted;
2125
} catch (e) {
2226
debugPrint('Error checking permissions: $e');
2327
}
@@ -27,28 +31,20 @@ class PermissionController extends GetxController {
2731
try {
2832
isLoading.value = true;
2933

30-
PermissionStatus storageStatus;
31-
if (GetPlatform.isAndroid) {
32-
storageStatus = await Permission.storage.request();
33-
} else {
34-
storageStatus = await Permission.photos.request();
35-
}
36-
isStorageGranted.value = storageStatus.isGranted;
37-
38-
final notificationStatus = await Permission.notification.request();
39-
isNotificationGranted.value = notificationStatus.isGranted;
40-
41-
if (isStorageGranted.value && isNotificationGranted.value) {
42-
Get.offNamed('/home');
34+
if (!isStorageGranted.value &&
35+
!isNotificationGranted.value &&
36+
!isExteternalStorageGranted.value) {
37+
await PermissionsManager.requestAllPermissions();
4338
}
39+
Get.offNamed('/home');
4440
} catch (e) {
4541
debugPrint('Error requesting permissions: $e');
4642
} finally {
4743
isLoading.value = false;
4844
}
4945
}
5046

51-
void openSettings() async {
47+
void gotoHome() async {
5248
try {
5349
await Get.offNamed('/home');
5450
} catch (e) {

lib/app/modules/permission/views/permission_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class PermissionView extends GetView<PermissionController> {
117117
)),
118118
const SizedBox(height: 16),
119119
TextButton(
120-
onPressed: () => controller.openSettings(),
120+
onPressed: () => controller.gotoHome(),
121121
style: ButtonStyle(
122122
backgroundColor:
123123
WidgetStateProperty.all(TaskWarriorColors.grey),

0 commit comments

Comments
 (0)