|
|
|
@ -27,7 +27,7 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
onPressed: () => Get.back(), |
|
|
|
), |
|
|
|
title: Text( |
|
|
|
'权限管理'.tr, |
|
|
|
'permissionManagement'.tr, // 权限管理 |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 17.sp, |
|
|
|
fontWeight: FontWeight.w600, |
|
|
|
@ -44,7 +44,9 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
} |
|
|
|
|
|
|
|
if (snapshot.hasError) { |
|
|
|
return Center(child: Text('获取权限状态失败: ${snapshot.error}'.tr)); |
|
|
|
return Center( |
|
|
|
child: Text('getPermissionStatusFailed'.tr + |
|
|
|
': ${snapshot.error}')); // 获取权限状态失败 |
|
|
|
} |
|
|
|
|
|
|
|
final permissionStatuses = snapshot.data ?? {}; |
|
|
|
@ -54,7 +56,7 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
children: [ |
|
|
|
// 通讯权限组 |
|
|
|
_buildPermissionSection( |
|
|
|
'通讯权限', |
|
|
|
'communicationPermissions'.tr, // 通讯权限 |
|
|
|
Icons.phone_android, |
|
|
|
[Permission.phone, Permission.sms], |
|
|
|
permissionStatuses, |
|
|
|
@ -64,7 +66,7 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
|
|
|
|
// 日历权限组 |
|
|
|
_buildPermissionSection( |
|
|
|
'日历权限', |
|
|
|
'calendarPermissions'.tr, // 日历权限 |
|
|
|
Icons.calendar_today, |
|
|
|
[Permission.calendarFullAccess], |
|
|
|
permissionStatuses, |
|
|
|
@ -73,8 +75,12 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
SizedBox(height: 20.h), |
|
|
|
|
|
|
|
// 位置权限组 |
|
|
|
_buildPermissionSection('位置权限', Icons.location_on, |
|
|
|
[Permission.location], permissionStatuses, isDarkMode), |
|
|
|
_buildPermissionSection( |
|
|
|
'locationPermissions'.tr, // 位置权限 |
|
|
|
Icons.location_on, |
|
|
|
[Permission.location], |
|
|
|
permissionStatuses, |
|
|
|
isDarkMode), |
|
|
|
], |
|
|
|
); |
|
|
|
}, |
|
|
|
@ -147,15 +153,15 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
String getName(Permission permission) { |
|
|
|
switch (permission) { |
|
|
|
case Permission.phone: |
|
|
|
return '电话'; |
|
|
|
return 'phone'.tr; // 电话 |
|
|
|
case Permission.sms: |
|
|
|
return '短信'; |
|
|
|
return 'sms'.tr; // 短信 |
|
|
|
case Permission.calendarFullAccess: |
|
|
|
return '日历写入'; |
|
|
|
return 'calendarWrite'.tr; // 日历写入 |
|
|
|
case Permission.calendarFullAccess: |
|
|
|
return '日历完整访问'; |
|
|
|
return 'calendarFullAccess'.tr; // 日历完整访问 |
|
|
|
case Permission.location: |
|
|
|
return '位置信息'; |
|
|
|
return 'locationInfo'.tr; // 位置信息 |
|
|
|
default: |
|
|
|
return permission.toString(); |
|
|
|
} |
|
|
|
@ -165,17 +171,17 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
String getDescription(Permission permission) { |
|
|
|
switch (permission) { |
|
|
|
case Permission.phone: |
|
|
|
return '用于拨打电话功能'; |
|
|
|
return 'phonePermissionDesc'.tr; // 用于拨打电话功能 |
|
|
|
case Permission.sms: |
|
|
|
return '用于发送短信功能'; |
|
|
|
return 'smsPermissionDesc'.tr; // 用于发送短信功能 |
|
|
|
case Permission.calendarFullAccess: |
|
|
|
return '用于创建日历事件和提醒'; |
|
|
|
return 'calendarWritePermissionDesc'.tr; // 用于创建日历事件和提醒 |
|
|
|
case Permission.calendarFullAccess: |
|
|
|
return '用于读取和管理日历事件及提醒'; |
|
|
|
return 'calendarFullAccessPermissionDesc'.tr; // 用于读取和管理日历事件及提醒 |
|
|
|
case Permission.location: |
|
|
|
return '用于获取当前位置信息'; |
|
|
|
return 'locationPermissionDesc'.tr; // 用于获取当前位置信息 |
|
|
|
default: |
|
|
|
return '应用功能需要'; |
|
|
|
return 'appFunctionNeeds'.tr; // 应用功能需要 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -265,19 +271,19 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
Color color; |
|
|
|
|
|
|
|
if (status.isGranted) { |
|
|
|
text = '已授权'.tr; |
|
|
|
text = 'authorized'.tr; // 已授权 |
|
|
|
color = Colors.green; |
|
|
|
} else if (status.isDenied) { |
|
|
|
text = '未授权'.tr; |
|
|
|
text = 'unauthorized'.tr; // 未授权 |
|
|
|
color = Colors.red; |
|
|
|
} else if (status.isPermanentlyDenied) { |
|
|
|
text = '需要在系统设置中开启'.tr; |
|
|
|
text = 'needOpenInSystemSettings'.tr; // 需要在系统设置中开启 |
|
|
|
color = Colors.orange; |
|
|
|
} else if (status.isLimited) { |
|
|
|
text = '部分授权'.tr; |
|
|
|
text = 'partialAuthorization'.tr; // 部分授权 |
|
|
|
color = Colors.orange; |
|
|
|
} else { |
|
|
|
text = '未知状态'.tr; |
|
|
|
text = 'unknownStatus'.tr; // 未知状态 |
|
|
|
color = Colors.grey; |
|
|
|
} |
|
|
|
|
|
|
|
@ -299,7 +305,7 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
// if (context == null) return; |
|
|
|
|
|
|
|
final permissionName = _getPermissionName(permission); |
|
|
|
final explanationText = _getExplanationText(permission); |
|
|
|
final explanationText = getDetailedDescription(permission); |
|
|
|
|
|
|
|
// 使用 PermissionUtil 请求权限 |
|
|
|
final hasPermission = await PermissionUtil.instance.requestPermission( |
|
|
|
@ -307,15 +313,16 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
permissionType: permission, |
|
|
|
permissionName: permissionName, |
|
|
|
explanationText: explanationText, |
|
|
|
permanentDenialText: '您已永久拒绝$permissionName权限,请前往应用设置开启', |
|
|
|
settingsButtonText: '去设置', |
|
|
|
cancelButtonText: '取消', |
|
|
|
permanentDenialText: 'permanentDenialText'.tr.replaceAll( |
|
|
|
'{permission}', permissionName), // 您已永久拒绝{permission}权限,请前往应用设置开启 |
|
|
|
settingsButtonText: 'goToSettings'.tr, // 去设置 |
|
|
|
cancelButtonText: 'cancel'.tr, // 取消 |
|
|
|
); |
|
|
|
|
|
|
|
if (hasPermission) { |
|
|
|
Get.snackbar( |
|
|
|
'成功'.tr, |
|
|
|
'$permissionName权限已授予'.tr, |
|
|
|
'success'.tr, // 成功 |
|
|
|
'permissionGranted'.tr, // 权限已授予 |
|
|
|
snackPosition: SnackPosition.BOTTOM, |
|
|
|
backgroundColor: Colors.green, |
|
|
|
colorText: Colors.white, |
|
|
|
@ -326,8 +333,8 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
Get.forceAppUpdate(); |
|
|
|
} catch (e) { |
|
|
|
Get.snackbar( |
|
|
|
'错误'.tr, |
|
|
|
'请求权限时出错: $e'.tr, |
|
|
|
'error'.tr, // 错误 |
|
|
|
'permissionRequestError'.tr, // 请求权限时出错 |
|
|
|
snackPosition: SnackPosition.BOTTOM, |
|
|
|
backgroundColor: Colors.red, |
|
|
|
colorText: Colors.white, |
|
|
|
@ -339,35 +346,35 @@ class PermissionsView extends GetView<SettingsController> { |
|
|
|
String _getPermissionName(Permission permission) { |
|
|
|
switch (permission) { |
|
|
|
case Permission.phone: |
|
|
|
return '电话'; |
|
|
|
return 'phone'.tr; // 电话 |
|
|
|
case Permission.sms: |
|
|
|
return '短信'; |
|
|
|
return 'sms'.tr; // 短信 |
|
|
|
case Permission.calendarFullAccess: |
|
|
|
return '日历写入'; |
|
|
|
return 'calendarWrite'.tr; // 日历写入 |
|
|
|
case Permission.calendarFullAccess: |
|
|
|
return '日历完整访问'; |
|
|
|
return 'calendarFullAccess'.tr; // 日历完整访问 |
|
|
|
case Permission.location: |
|
|
|
return '位置信息'; |
|
|
|
return 'locationInfo'.tr; // 位置信息 |
|
|
|
default: |
|
|
|
return permission.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 获取权限说明文本 |
|
|
|
String _getExplanationText(Permission permission) { |
|
|
|
String getDetailedDescription(Permission permission) { |
|
|
|
switch (permission) { |
|
|
|
case Permission.phone: |
|
|
|
return '拨打电话功能需要电话权限'; |
|
|
|
return 'phonePermissionDetailDesc'.tr; // 拨打电话功能需要电话权限 |
|
|
|
case Permission.sms: |
|
|
|
return '发送短信功能需要短信权限'; |
|
|
|
return 'smsPermissionDetailDesc'.tr; // 发送短信功能需要短信权限 |
|
|
|
case Permission.calendarFullAccess: |
|
|
|
return '创建日历事件需要日历写入权限'; |
|
|
|
return 'calendarWritePermissionDetailDesc'.tr; // 创建日历事件需要日历写入权限 |
|
|
|
case Permission.calendarFullAccess: |
|
|
|
return '管理日历事件需要完整日历权限'; |
|
|
|
return 'calendarFullAccessPermissionDetailDesc'.tr; // 管理日历事件需要完整日历权限 |
|
|
|
case Permission.location: |
|
|
|
return '获取位置信息需要位置权限'; |
|
|
|
return 'locationPermissionDetailDesc'.tr; // 获取位置信息需要位置权限 |
|
|
|
default: |
|
|
|
return '应用需要此权限以提供完整功能'; |
|
|
|
return 'appNeedsPermissionForFullFunction'.tr; // 应用需要此权限以提供完整功能 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|