|
| 1 | +import 'dart:io'; |
| 2 | + |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:get/get.dart'; |
| 5 | +import 'package:taskwarrior/app/modules/permission/views/permission_section.dart'; |
| 6 | +import 'package:taskwarrior/app/utils/app_settings/app_settings.dart'; |
| 7 | +import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart'; |
| 8 | +import '../controllers/permission_controller.dart'; |
| 9 | + |
| 10 | +class PermissionView extends GetView<PermissionController> { |
| 11 | + const PermissionView({super.key}); |
| 12 | + |
| 13 | + @override |
| 14 | + Widget build(BuildContext context) { |
| 15 | + final isDarkMode = Theme.of(context).brightness == Brightness.dark; |
| 16 | + |
| 17 | + if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) { |
| 18 | + WidgetsBinding.instance.addPostFrameCallback((_) { |
| 19 | + Get.offAllNamed('/home'); |
| 20 | + }); |
| 21 | + return const SizedBox.shrink(); |
| 22 | + } |
| 23 | + |
| 24 | + return Scaffold( |
| 25 | + backgroundColor: isDarkMode |
| 26 | + ? TaskWarriorColors.kprimaryBackgroundColor |
| 27 | + : TaskWarriorColors.kLightPrimaryBackgroundColor, |
| 28 | + body: SafeArea( |
| 29 | + child: SingleChildScrollView( |
| 30 | + child: Padding( |
| 31 | + padding: const EdgeInsets.all(24.0), |
| 32 | + child: Column( |
| 33 | + crossAxisAlignment: CrossAxisAlignment.stretch, |
| 34 | + children: [ |
| 35 | + const SizedBox(height: 24), |
| 36 | + Text( |
| 37 | + 'Why We Need Your Permission', |
| 38 | + style: Theme.of(context).textTheme.headlineMedium?.copyWith( |
| 39 | + fontWeight: FontWeight.bold, |
| 40 | + color: isDarkMode |
| 41 | + ? TaskWarriorColors.kprimaryTextColor |
| 42 | + : TaskWarriorColors.kLightPrimaryTextColor, |
| 43 | + ), |
| 44 | + textAlign: TextAlign.center, |
| 45 | + ), |
| 46 | + const SizedBox(height: 32), |
| 47 | + Icon( |
| 48 | + Icons.security, |
| 49 | + size: 64, |
| 50 | + color: AppSettings.isDarkMode |
| 51 | + ? TaskWarriorColors.black |
| 52 | + : TaskWarriorColors.white, |
| 53 | + ), |
| 54 | + const SizedBox(height: 32), |
| 55 | + PermissionSection( |
| 56 | + icon: Icons.folder_outlined, |
| 57 | + title: 'Storage Permission', |
| 58 | + description: |
| 59 | + 'We use storage access to save your tasks, preferences, ' |
| 60 | + 'and app data securely on your device. This ensures that you can ' |
| 61 | + 'pick up where you left off seamlessly, even offline.', |
| 62 | + isDarkMode: isDarkMode, |
| 63 | + ), |
| 64 | + const SizedBox(height: 24), |
| 65 | + PermissionSection( |
| 66 | + icon: Icons.notifications_outlined, |
| 67 | + title: 'Notification Permission', |
| 68 | + description: |
| 69 | + 'Notifications keep you updated with important reminders ' |
| 70 | + 'and updates, ensuring you stay on top of your tasks effortlessly.', |
| 71 | + isDarkMode: isDarkMode, |
| 72 | + ), |
| 73 | + const SizedBox(height: 24), |
| 74 | + Text( |
| 75 | + 'Your privacy is our top priority. We never access or share your ' |
| 76 | + 'personal files or data without your consent.', |
| 77 | + style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 78 | + color: AppSettings.isDarkMode |
| 79 | + ? TaskWarriorColors.black |
| 80 | + : TaskWarriorColors.white, |
| 81 | + ), |
| 82 | + textAlign: TextAlign.center, |
| 83 | + ), |
| 84 | + const SizedBox(height: 48), |
| 85 | + Obx(() => ElevatedButton( |
| 86 | + onPressed: controller.isLoading.value |
| 87 | + ? null |
| 88 | + : controller.requestPermissions, |
| 89 | + style: ElevatedButton.styleFrom( |
| 90 | + padding: const EdgeInsets.all(16), |
| 91 | + backgroundColor: AppSettings.isDarkMode |
| 92 | + ? TaskWarriorColors.black |
| 93 | + : TaskWarriorColors.white, |
| 94 | + foregroundColor: AppSettings.isDarkMode |
| 95 | + ? TaskWarriorColors.kprimaryTextColor |
| 96 | + : TaskWarriorColors.kLightPrimaryTextColor, |
| 97 | + shape: RoundedRectangleBorder( |
| 98 | + borderRadius: BorderRadius.circular(12), |
| 99 | + ), |
| 100 | + ), |
| 101 | + child: controller.isLoading.value |
| 102 | + ? CircularProgressIndicator( |
| 103 | + color: AppSettings.isDarkMode |
| 104 | + ? TaskWarriorColors.black |
| 105 | + : TaskWarriorColors.white, |
| 106 | + ) |
| 107 | + : Text( |
| 108 | + 'Grant Permissions', |
| 109 | + style: TextStyle( |
| 110 | + color: AppSettings.isDarkMode |
| 111 | + ? TaskWarriorColors.kprimaryTextColor |
| 112 | + : TaskWarriorColors.kLightPrimaryTextColor, |
| 113 | + fontSize: 16, |
| 114 | + ), |
| 115 | + ), |
| 116 | + )), |
| 117 | + const SizedBox(height: 16), |
| 118 | + TextButton( |
| 119 | + onPressed: () => controller.gotoHome(), |
| 120 | + style: ButtonStyle( |
| 121 | + backgroundColor: |
| 122 | + WidgetStateProperty.all(TaskWarriorColors.grey), |
| 123 | + ), |
| 124 | + child: Text( |
| 125 | + 'You can manage your permissions anytime later in Settings', |
| 126 | + style: Theme.of(context).textTheme.bodySmall?.copyWith( |
| 127 | + color: AppSettings.isDarkMode |
| 128 | + ? TaskWarriorColors.black |
| 129 | + : TaskWarriorColors.white, |
| 130 | + ), |
| 131 | + textAlign: TextAlign.center, |
| 132 | + ), |
| 133 | + ), |
| 134 | + const SizedBox(height: 24), |
| 135 | + ], |
| 136 | + ), |
| 137 | + ), |
| 138 | + ), |
| 139 | + ), |
| 140 | + ); |
| 141 | + } |
| 142 | +} |
0 commit comments