|
| 1 | +import 'dart:io'; |
| 2 | + |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:get/get.dart'; |
| 5 | +import 'package:taskwarrior/app/utils/app_settings/app_settings.dart'; |
| 6 | +import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart'; |
| 7 | +import '../controllers/permission_controller.dart'; |
| 8 | + |
| 9 | +class PermissionView extends GetView<PermissionController> { |
| 10 | + const PermissionView({super.key}); |
| 11 | + |
| 12 | + @override |
| 13 | + Widget build(BuildContext context) { |
| 14 | + final isDarkMode = Theme.of(context).brightness == Brightness.dark; |
| 15 | + |
| 16 | + if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) { |
| 17 | + WidgetsBinding.instance.addPostFrameCallback((_) { |
| 18 | + Get.offAllNamed('/home'); |
| 19 | + }); |
| 20 | + return const SizedBox.shrink(); |
| 21 | + } |
| 22 | + |
| 23 | + return Scaffold( |
| 24 | + backgroundColor: isDarkMode |
| 25 | + ? TaskWarriorColors.kprimaryBackgroundColor |
| 26 | + : TaskWarriorColors.kLightPrimaryBackgroundColor, |
| 27 | + body: SafeArea( |
| 28 | + child: SingleChildScrollView( |
| 29 | + child: Padding( |
| 30 | + padding: const EdgeInsets.all(24.0), |
| 31 | + child: Column( |
| 32 | + crossAxisAlignment: CrossAxisAlignment.stretch, |
| 33 | + children: [ |
| 34 | + const SizedBox(height: 24), |
| 35 | + Text( |
| 36 | + 'Why We Need Your Permission', |
| 37 | + style: Theme.of(context).textTheme.headlineMedium?.copyWith( |
| 38 | + fontWeight: FontWeight.bold, |
| 39 | + color: isDarkMode |
| 40 | + ? TaskWarriorColors.kprimaryTextColor |
| 41 | + : TaskWarriorColors.kLightPrimaryTextColor, |
| 42 | + ), |
| 43 | + textAlign: TextAlign.center, |
| 44 | + ), |
| 45 | + const SizedBox(height: 32), |
| 46 | + Icon( |
| 47 | + Icons.security, |
| 48 | + size: 64, |
| 49 | + color: AppSettings.isDarkMode |
| 50 | + ? TaskWarriorColors.black |
| 51 | + : TaskWarriorColors.white, |
| 52 | + ), |
| 53 | + const SizedBox(height: 32), |
| 54 | + _buildPermissionSection( |
| 55 | + context, |
| 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 | + _buildPermissionSection( |
| 66 | + context, |
| 67 | + icon: Icons.notifications_outlined, |
| 68 | + title: 'Notification Permission', |
| 69 | + description: |
| 70 | + 'Notifications keep you updated with important reminders ' |
| 71 | + 'and updates, ensuring you stay on top of your tasks effortlessly.', |
| 72 | + isDarkMode: isDarkMode, |
| 73 | + ), |
| 74 | + const SizedBox(height: 24), |
| 75 | + Text( |
| 76 | + 'Your privacy is our top priority. We never access or share your ' |
| 77 | + 'personal files or data without your consent.', |
| 78 | + style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 79 | + color: AppSettings.isDarkMode |
| 80 | + ? TaskWarriorColors.black |
| 81 | + : TaskWarriorColors.white, |
| 82 | + ), |
| 83 | + textAlign: TextAlign.center, |
| 84 | + ), |
| 85 | + const SizedBox(height: 48), |
| 86 | + Obx(() => ElevatedButton( |
| 87 | + onPressed: controller.isLoading.value |
| 88 | + ? null |
| 89 | + : controller.requestPermissions, |
| 90 | + style: ElevatedButton.styleFrom( |
| 91 | + padding: const EdgeInsets.all(16), |
| 92 | + backgroundColor: AppSettings.isDarkMode |
| 93 | + ? TaskWarriorColors.black |
| 94 | + : TaskWarriorColors.white, |
| 95 | + foregroundColor: AppSettings.isDarkMode |
| 96 | + ? TaskWarriorColors.kprimaryTextColor |
| 97 | + : TaskWarriorColors.kLightPrimaryTextColor, |
| 98 | + shape: RoundedRectangleBorder( |
| 99 | + borderRadius: BorderRadius.circular(12), |
| 100 | + ), |
| 101 | + ), |
| 102 | + child: controller.isLoading.value |
| 103 | + ? CircularProgressIndicator( |
| 104 | + color: AppSettings.isDarkMode |
| 105 | + ? TaskWarriorColors.black |
| 106 | + : TaskWarriorColors.white, |
| 107 | + ) |
| 108 | + : Text( |
| 109 | + 'Grant Permissions', |
| 110 | + style: TextStyle( |
| 111 | + color: AppSettings.isDarkMode |
| 112 | + ? TaskWarriorColors.kprimaryTextColor |
| 113 | + : TaskWarriorColors.kLightPrimaryTextColor, |
| 114 | + fontSize: 16, |
| 115 | + ), |
| 116 | + ), |
| 117 | + )), |
| 118 | + const SizedBox(height: 16), |
| 119 | + TextButton( |
| 120 | + onPressed: () => controller.openSettings(), |
| 121 | + style: ButtonStyle( |
| 122 | + backgroundColor: |
| 123 | + WidgetStateProperty.all(TaskWarriorColors.grey), |
| 124 | + ), |
| 125 | + child: Text( |
| 126 | + 'You can manage your permissions anytime later in Settings', |
| 127 | + style: Theme.of(context).textTheme.bodySmall?.copyWith( |
| 128 | + color: AppSettings.isDarkMode |
| 129 | + ? TaskWarriorColors.black |
| 130 | + : TaskWarriorColors.white, |
| 131 | + ), |
| 132 | + textAlign: TextAlign.center, |
| 133 | + ), |
| 134 | + ), |
| 135 | + const SizedBox(height: 24), |
| 136 | + ], |
| 137 | + ), |
| 138 | + ), |
| 139 | + ), |
| 140 | + ), |
| 141 | + ); |
| 142 | + } |
| 143 | + |
| 144 | + Widget _buildPermissionSection( |
| 145 | + BuildContext context, { |
| 146 | + required IconData icon, |
| 147 | + required String title, |
| 148 | + required String description, |
| 149 | + required bool isDarkMode, |
| 150 | + }) { |
| 151 | + return Container( |
| 152 | + padding: const EdgeInsets.all(16), |
| 153 | + decoration: BoxDecoration( |
| 154 | + border: Border.all( |
| 155 | + color: isDarkMode |
| 156 | + ? TaskWarriorColors.ksecondaryBackgroundColor |
| 157 | + : TaskWarriorColors.borderColor, |
| 158 | + ), |
| 159 | + borderRadius: BorderRadius.circular(12), |
| 160 | + color: isDarkMode |
| 161 | + ? TaskWarriorColors.kdialogBackGroundColor |
| 162 | + : TaskWarriorColors.kLightDialogBackGroundColor, |
| 163 | + ), |
| 164 | + child: Column( |
| 165 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 166 | + children: [ |
| 167 | + Row( |
| 168 | + children: [ |
| 169 | + Icon(icon, color: TaskWarriorColors.black), |
| 170 | + const SizedBox(width: 12), |
| 171 | + Expanded( |
| 172 | + child: Text( |
| 173 | + title, |
| 174 | + style: Theme.of(context).textTheme.titleMedium?.copyWith( |
| 175 | + fontWeight: FontWeight.bold, |
| 176 | + color: isDarkMode |
| 177 | + ? TaskWarriorColors.kprimaryTextColor |
| 178 | + : TaskWarriorColors.kLightPrimaryTextColor, |
| 179 | + ), |
| 180 | + ), |
| 181 | + ), |
| 182 | + ], |
| 183 | + ), |
| 184 | + const SizedBox(height: 8), |
| 185 | + Text( |
| 186 | + description, |
| 187 | + style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 188 | + color: isDarkMode |
| 189 | + ? TaskWarriorColors.ksecondaryTextColor |
| 190 | + : TaskWarriorColors.kLightSecondaryTextColor, |
| 191 | + ), |
| 192 | + ), |
| 193 | + ], |
| 194 | + ), |
| 195 | + ); |
| 196 | + } |
| 197 | +} |
0 commit comments