diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index cd303fc2..2a7e6d49 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -3,6 +3,8 @@ + + diff --git a/lib/app/modules/settings/controllers/settings_controller.dart b/lib/app/modules/settings/controllers/settings_controller.dart index ed6e8c96..15987b3e 100644 --- a/lib/app/modules/settings/controllers/settings_controller.dart +++ b/lib/app/modules/settings/controllers/settings_controller.dart @@ -62,6 +62,7 @@ class SettingsController extends GetxController { profilesWidget.setBaseDirectory(destination); SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.setString('baseDirectory', destination.path); + baseDirectory.value = destination.path; } else { showDialog( context: context, diff --git a/lib/app/modules/settings/views/settings_page_select_directory_list_tile.dart b/lib/app/modules/settings/views/settings_page_select_directory_list_tile.dart index b5afb17c..ae7f7cd5 100644 --- a/lib/app/modules/settings/views/settings_page_select_directory_list_tile.dart +++ b/lib/app/modules/settings/views/settings_page_select_directory_list_tile.dart @@ -136,6 +136,7 @@ class SettingsPageSelectDirectoryListTile extends StatelessWidget { await SharedPreferences.getInstance(); await prefs.remove('baseDirectory'); controller.isMovingDirectory.value = false; + controller.baseDirectory.value = "Default"; }); }, child: Text( diff --git a/lib/app/utils/constants/permissions.dart b/lib/app/utils/constants/permissions.dart new file mode 100644 index 00000000..96bc05dc --- /dev/null +++ b/lib/app/utils/constants/permissions.dart @@ -0,0 +1,7 @@ +import 'package:permission_handler/permission_handler.dart'; + +List permissions = [ + Permission.notification, + Permission.storage, + Permission.manageExternalStorage, +]; \ No newline at end of file diff --git a/lib/app/utils/permissions/permissions_manager.dart b/lib/app/utils/permissions/permissions_manager.dart new file mode 100644 index 00000000..d137a3da --- /dev/null +++ b/lib/app/utils/permissions/permissions_manager.dart @@ -0,0 +1,27 @@ +// ignore_for_file: avoid_print + +import 'package:permission_handler/permission_handler.dart'; +import 'package:taskwarrior/app/utils/constants/permissions.dart'; + +class PermissionsManager { + static Future requestAllPermissions() async { + try { + for (var permission in permissions) { + final status = await _requestPermission(permission); + + if (status) { + print("Permission '${permission.toString().split('.').last}' granted."); + } else { + print("Permission '${permission.toString().split('.').last}' denied."); + } + } + } catch (e) { + print("Error requesting permissions: $e"); + } + } + + static Future _requestPermission(Permission permission) async { + final status = await permission.request(); + return status.isGranted; + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index a0a423c4..a88ff580 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,20 +1,16 @@ import 'package:flutter/material.dart'; - import 'package:get/get.dart'; -import 'package:permission_handler/permission_handler.dart'; import 'package:taskwarrior/app/utils/app_settings/app_settings.dart'; - +import 'package:taskwarrior/app/utils/permissions/permissions_manager.dart'; import 'app/routes/app_pages.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await AppSettings.init(); - await Permission.notification.isDenied.then((value) { - if (value) { - Permission.notification.request(); - } - }); + await PermissionsManager.requestAllPermissions(); + + runApp( GetMaterialApp( title: "Application",