From 63a35f70b732ba3a40851f08fc14d5bdaf767107 Mon Sep 17 00:00:00 2001 From: Shubham04jha Date: Tue, 5 Nov 2024 12:04:27 +0530 Subject: [PATCH 1/4] loading screen bug fixed, by giving permissions --- android/app/src/main/AndroidManifest.xml | 2 ++ .../about/controllers/about_controller.dart | 2 +- lib/main.dart | 31 ++++++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) 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/about/controllers/about_controller.dart b/lib/app/modules/about/controllers/about_controller.dart index 119d4163..a85c7394 100644 --- a/lib/app/modules/about/controllers/about_controller.dart +++ b/lib/app/modules/about/controllers/about_controller.dart @@ -1,6 +1,6 @@ import 'package:get/get.dart'; import 'package:taskwarrior/app/utils/language/supported_language.dart'; -import 'package:taskwarrior/app/utils/theme/app_settings.dart'; +import 'package:taskwarrior/app/utils/app_settings/app_settings.dart'; class AboutController extends GetxController { final Rx selectedLanguage = SupportedLanguage.english.obs; diff --git a/lib/main.dart b/lib/main.dart index a0a423c4..6f56a33a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -10,11 +10,34 @@ void main() async { WidgetsFlutterBinding.ensureInitialized(); await AppSettings.init(); - await Permission.notification.isDenied.then((value) { - if (value) { - Permission.notification.request(); + // await Permission.notification.isDenied.then((value) { + // if (value) { + // Permission.notification.request(); + // } + // }); + if (await Permission.notification.isDenied) { + if (await Permission.notification.request().isGranted) { + print("Notification permission granted"); + } else { + print("Notification permission denied"); } - }); + } + + if (await Permission.storage.isDenied) { + if (await Permission.storage.request().isGranted) { + print("Storage permission granted"); + } else { + print("Storage permission denied"); + } + } + + if (await Permission.manageExternalStorage.isDenied) { + if (await Permission.manageExternalStorage.request().isGranted) { + print("Manage external storage permission granted"); + } else { + print("Manage external storage permission denied"); + } + } runApp( GetMaterialApp( title: "Application", From 26ed818f0dbb6a490df1c14727946033072a19ed Mon Sep 17 00:00:00 2001 From: Shubham04jha Date: Tue, 5 Nov 2024 12:21:16 +0530 Subject: [PATCH 2/4] abstracted the permission logic and solved the bugs --- .../controllers/settings_controller.dart | 1 + ...tings_page_select_directory_list_tile.dart | 1 + lib/app/utils/constants/permissions.dart | 7 ++++ .../permissions/permissions_manager.dart | 33 +++++++++++++++++++ lib/main.dart | 32 ++---------------- 5 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 lib/app/utils/constants/permissions.dart create mode 100644 lib/app/utils/permissions/permissions_manager.dart 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..a17a7582 --- /dev/null +++ b/lib/app/utils/permissions/permissions_manager.dart @@ -0,0 +1,33 @@ +// 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 { + final results = await Future.wait( + permissions.map((permission) => _requestPermission(permission))); + + for (var i = 0; i < results.length; i++) { + final permission = permissions[i]; + final status = results[i]; + + 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 6f56a33a..79bf904e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,43 +1,17 @@ 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(); - // } - // }); - if (await Permission.notification.isDenied) { - if (await Permission.notification.request().isGranted) { - print("Notification permission granted"); - } else { - print("Notification permission denied"); - } - } + await PermissionsManager.requestAllPermissions(); - if (await Permission.storage.isDenied) { - if (await Permission.storage.request().isGranted) { - print("Storage permission granted"); - } else { - print("Storage permission denied"); - } - } - if (await Permission.manageExternalStorage.isDenied) { - if (await Permission.manageExternalStorage.request().isGranted) { - print("Manage external storage permission granted"); - } else { - print("Manage external storage permission denied"); - } - } runApp( GetMaterialApp( title: "Application", @@ -45,4 +19,4 @@ void main() async { getPages: AppPages.routes, ), ); -} +} \ No newline at end of file From d103e46d11591d15db926ccda7ea438531532da0 Mon Sep 17 00:00:00 2001 From: Shubham04jha Date: Tue, 5 Nov 2024 12:53:20 +0530 Subject: [PATCH 3/4] added await for taking the response first --- .../utils/permissions/permissions_manager.dart | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/app/utils/permissions/permissions_manager.dart b/lib/app/utils/permissions/permissions_manager.dart index a17a7582..d137a3da 100644 --- a/lib/app/utils/permissions/permissions_manager.dart +++ b/lib/app/utils/permissions/permissions_manager.dart @@ -6,19 +6,13 @@ import 'package:taskwarrior/app/utils/constants/permissions.dart'; class PermissionsManager { static Future requestAllPermissions() async { try { - final results = await Future.wait( - permissions.map((permission) => _requestPermission(permission))); - - for (var i = 0; i < results.length; i++) { - final permission = permissions[i]; - final status = results[i]; - + for (var permission in permissions) { + final status = await _requestPermission(permission); + if (status) { - print( - "Permission '${permission.toString().split('.').last}' granted."); + print("Permission '${permission.toString().split('.').last}' granted."); } else { - print( - "Permission '${permission.toString().split('.').last}' denied."); + print("Permission '${permission.toString().split('.').last}' denied."); } } } catch (e) { From b6fe7450cd0442e5f505c6fe36ca29a9f1ac5ab1 Mon Sep 17 00:00:00 2001 From: Chinmay Chaudhari <111864031+BrawlerXull@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:16:56 +0530 Subject: [PATCH 4/4] Removed unused import --- lib/main.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 79bf904e..a88ff580 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,5 @@ 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'; @@ -19,4 +18,4 @@ void main() async { getPages: AppPages.routes, ), ); -} \ No newline at end of file +}