Browse Source

fix(permission): 适配权限提示对话框暗黑模式

- 获取当前主题模式判断是否为暗黑模式
- 权限提示对话框背景色根据主题切换
- 调整标题和内容文字颜色以适配暗黑模式
- 修改按钮样式颜色使其在暗黑模式下更清晰
- 优化对话框内文本样式,提升视觉体验
newdev_shunjiawei
lxm 7 months ago
parent
commit
8458ed7d14
  1. 47
      lib/core/utils/permission_util.dart

47
lib/core/utils/permission_util.dart

@ -164,6 +164,12 @@ class PermissionUtil {
required String permissionName,
required String explanationText,
}) {
// 获取当前主题模式
final context = Get.context;
final isDarkMode = context != null
? Theme.of(context).brightness == Brightness.dark
: false;
Get.dialog(
Stack(
children: [
@ -174,7 +180,7 @@ class PermissionUtil {
child: Material(
borderRadius: BorderRadius.circular(12),
elevation: 8,
color: Colors.grey[300],
color: isDarkMode ? const Color(0xFF2D2D2D) : Colors.grey[300],
shadowColor: Colors.black.withValues(alpha: 0.3),
child: Padding(
padding: const EdgeInsets.all(16),
@ -186,15 +192,19 @@ class PermissionUtil {
'permissionUtilNeed'.tr +
permissionName +
'permissionUtilPermission'.tr,
style: const TextStyle(
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: isDarkMode ? Colors.white : Colors.black87,
),
),
const SizedBox(height: 8),
Text(
explanationText,
style: const TextStyle(fontSize: 14),
style: TextStyle(
fontSize: 14,
color: isDarkMode ? Colors.white70 : Colors.black54,
),
),
],
),
@ -227,18 +237,38 @@ class PermissionUtil {
}) async {
Logger.i('PermissionUtil', '显示永久拒绝对话框 ($permissionName)');
// 获取当前主题模式
final context = Get.context;
final isDarkMode = context != null
? Theme.of(context).brightness == Brightness.dark
: false;
bool? userChoice = await Get.dialog(
AlertDialog(
title: Text('permissionUtilNeed'.tr +
backgroundColor: isDarkMode ? const Color(0xFF2D2D2D) : Colors.white,
title: Text(
'permissionUtilNeed'.tr +
permissionName +
'permissionUtilPermission'.tr),
content: Text(permanentDenialText),
'permissionUtilPermission'.tr,
style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black87,
),
),
content: Text(
permanentDenialText,
style: TextStyle(
color: isDarkMode ? Colors.white70 : Colors.black54,
),
),
actions: [
TextButton(
onPressed: () {
Logger.d('PermissionUtil', '用户取消设置 ($permissionName)');
Get.back(result: false);
},
style: TextButton.styleFrom(
foregroundColor: isDarkMode ? Colors.white70 : Colors.grey[700],
),
child: Text(cancelButtonText),
),
ElevatedButton(
@ -246,6 +276,11 @@ class PermissionUtil {
Logger.d('PermissionUtil', '用户同意前往设置 ($permissionName)');
Get.back(result: true);
},
style: ElevatedButton.styleFrom(
backgroundColor:
isDarkMode ? const Color(0xFF0066CC) : Colors.blue,
foregroundColor: Colors.white,
),
child: Text(settingsButtonText),
),
],

Loading…
Cancel
Save