-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #432 from rohansen856/permission_screen
feat: added permission request screen
- Loading branch information
Showing
9 changed files
with
285 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
lib/app/modules/permission/bindings/permission_binding.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:get/get.dart'; | ||
|
||
import '../controllers/permission_controller.dart'; | ||
|
||
class PermissionBinding extends Bindings { | ||
@override | ||
void dependencies() { | ||
Get.lazyPut<PermissionController>( | ||
() => PermissionController(), | ||
); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
lib/app/modules/permission/controllers/permission_controller.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:permission_handler/permission_handler.dart'; | ||
import 'package:taskwarrior/app/utils/permissions/permissions_manager.dart'; | ||
|
||
class PermissionController extends GetxController { | ||
final RxBool isStorageGranted = false.obs; | ||
final RxBool isNotificationGranted = false.obs; | ||
final RxBool isExteternalStorageGranted = false.obs; | ||
final RxBool isLoading = false.obs; | ||
|
||
@override | ||
void onInit() { | ||
super.onInit(); | ||
checkPermissions(); | ||
} | ||
|
||
Future<void> checkPermissions() async { | ||
try { | ||
isStorageGranted.value = await Permission.storage.status.isGranted; | ||
isNotificationGranted.value = | ||
await Permission.notification.status.isGranted; | ||
isExteternalStorageGranted.value = | ||
await Permission.manageExternalStorage.status.isGranted; | ||
} catch (e) { | ||
debugPrint('Error checking permissions: $e'); | ||
} | ||
} | ||
|
||
Future<void> requestPermissions() async { | ||
try { | ||
isLoading.value = true; | ||
|
||
if (!isStorageGranted.value && | ||
!isNotificationGranted.value && | ||
!isExteternalStorageGranted.value) { | ||
await PermissionsManager.requestAllPermissions(); | ||
} | ||
Get.offNamed('/home'); | ||
} catch (e) { | ||
debugPrint('Error requesting permissions: $e'); | ||
} finally { | ||
isLoading.value = false; | ||
} | ||
} | ||
|
||
void gotoHome() async { | ||
try { | ||
await Get.offNamed('/home'); | ||
} catch (e) { | ||
debugPrint('Error opening home screen: $e'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart'; | ||
|
||
class PermissionSection extends StatelessWidget { | ||
final IconData icon; | ||
final String title; | ||
final String description; | ||
final bool isDarkMode; | ||
|
||
const PermissionSection({ | ||
super.key, | ||
required this.icon, | ||
required this.title, | ||
required this.description, | ||
required this.isDarkMode, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
padding: const EdgeInsets.all(16), | ||
decoration: BoxDecoration( | ||
border: Border.all( | ||
color: isDarkMode | ||
? TaskWarriorColors.ksecondaryBackgroundColor | ||
: TaskWarriorColors.borderColor, | ||
), | ||
borderRadius: BorderRadius.circular(12), | ||
color: isDarkMode | ||
? TaskWarriorColors.kdialogBackGroundColor | ||
: TaskWarriorColors.kLightDialogBackGroundColor, | ||
), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Row( | ||
children: [ | ||
Icon(icon, color: TaskWarriorColors.black), | ||
const SizedBox(width: 12), | ||
Expanded( | ||
child: Text( | ||
title, | ||
style: Theme.of(context).textTheme.titleMedium?.copyWith( | ||
fontWeight: FontWeight.bold, | ||
color: isDarkMode | ||
? TaskWarriorColors.kprimaryTextColor | ||
: TaskWarriorColors.kLightPrimaryTextColor, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
const SizedBox(height: 8), | ||
Text( | ||
description, | ||
style: Theme.of(context).textTheme.bodyMedium?.copyWith( | ||
color: isDarkMode | ||
? TaskWarriorColors.ksecondaryTextColor | ||
: TaskWarriorColors.kLightSecondaryTextColor, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:taskwarrior/app/modules/permission/views/permission_section.dart'; | ||
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart'; | ||
import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart'; | ||
import '../controllers/permission_controller.dart'; | ||
|
||
class PermissionView extends GetView<PermissionController> { | ||
const PermissionView({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final isDarkMode = Theme.of(context).brightness == Brightness.dark; | ||
|
||
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) { | ||
WidgetsBinding.instance.addPostFrameCallback((_) { | ||
Get.offAllNamed('/home'); | ||
}); | ||
return const SizedBox.shrink(); | ||
} | ||
|
||
return Scaffold( | ||
backgroundColor: isDarkMode | ||
? TaskWarriorColors.kprimaryBackgroundColor | ||
: TaskWarriorColors.kLightPrimaryBackgroundColor, | ||
body: SafeArea( | ||
child: SingleChildScrollView( | ||
child: Padding( | ||
padding: const EdgeInsets.all(24.0), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
const SizedBox(height: 24), | ||
Text( | ||
'Why We Need Your Permission', | ||
style: Theme.of(context).textTheme.headlineMedium?.copyWith( | ||
fontWeight: FontWeight.bold, | ||
color: isDarkMode | ||
? TaskWarriorColors.kprimaryTextColor | ||
: TaskWarriorColors.kLightPrimaryTextColor, | ||
), | ||
textAlign: TextAlign.center, | ||
), | ||
const SizedBox(height: 32), | ||
Icon( | ||
Icons.security, | ||
size: 64, | ||
color: AppSettings.isDarkMode | ||
? TaskWarriorColors.black | ||
: TaskWarriorColors.white, | ||
), | ||
const SizedBox(height: 32), | ||
PermissionSection( | ||
icon: Icons.folder_outlined, | ||
title: 'Storage Permission', | ||
description: | ||
'We use storage access to save your tasks, preferences, ' | ||
'and app data securely on your device. This ensures that you can ' | ||
'pick up where you left off seamlessly, even offline.', | ||
isDarkMode: isDarkMode, | ||
), | ||
const SizedBox(height: 24), | ||
PermissionSection( | ||
icon: Icons.notifications_outlined, | ||
title: 'Notification Permission', | ||
description: | ||
'Notifications keep you updated with important reminders ' | ||
'and updates, ensuring you stay on top of your tasks effortlessly.', | ||
isDarkMode: isDarkMode, | ||
), | ||
const SizedBox(height: 24), | ||
Text( | ||
'Your privacy is our top priority. We never access or share your ' | ||
'personal files or data without your consent.', | ||
style: Theme.of(context).textTheme.bodyMedium?.copyWith( | ||
color: AppSettings.isDarkMode | ||
? TaskWarriorColors.black | ||
: TaskWarriorColors.white, | ||
), | ||
textAlign: TextAlign.center, | ||
), | ||
const SizedBox(height: 48), | ||
Obx(() => ElevatedButton( | ||
onPressed: controller.isLoading.value | ||
? null | ||
: controller.requestPermissions, | ||
style: ElevatedButton.styleFrom( | ||
padding: const EdgeInsets.all(16), | ||
backgroundColor: AppSettings.isDarkMode | ||
? TaskWarriorColors.black | ||
: TaskWarriorColors.white, | ||
foregroundColor: AppSettings.isDarkMode | ||
? TaskWarriorColors.kprimaryTextColor | ||
: TaskWarriorColors.kLightPrimaryTextColor, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(12), | ||
), | ||
), | ||
child: controller.isLoading.value | ||
? CircularProgressIndicator( | ||
color: AppSettings.isDarkMode | ||
? TaskWarriorColors.black | ||
: TaskWarriorColors.white, | ||
) | ||
: Text( | ||
'Grant Permissions', | ||
style: TextStyle( | ||
color: AppSettings.isDarkMode | ||
? TaskWarriorColors.kprimaryTextColor | ||
: TaskWarriorColors.kLightPrimaryTextColor, | ||
fontSize: 16, | ||
), | ||
), | ||
)), | ||
const SizedBox(height: 16), | ||
TextButton( | ||
onPressed: () => controller.gotoHome(), | ||
style: ButtonStyle( | ||
backgroundColor: | ||
WidgetStateProperty.all(TaskWarriorColors.grey), | ||
), | ||
child: Text( | ||
'You can manage your permissions anytime later in Settings', | ||
style: Theme.of(context).textTheme.bodySmall?.copyWith( | ||
color: AppSettings.isDarkMode | ||
? TaskWarriorColors.black | ||
: TaskWarriorColors.white, | ||
), | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
const SizedBox(height: 24), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters