Browse Source

feat(权限): 在权限视图顶部添加后台权限设置入口,仅对Android中文环境用户显示。包含完整的品牌定制化设置指南,帮助用户正确配置后台运行权限以确保AI助手随时响应。

newdev_shunjiawei
lxm 1 year ago
parent
commit
5b9c2c6bf8
  1. 288
      lib/modules/permissions/views/permissions_view.dart
  2. 2
      pubspec.yaml

288
lib/modules/permissions/views/permissions_view.dart

@ -69,6 +69,15 @@ class PermissionsView extends GetView<PermissionsController> {
final groups = snapshot.data ?? [];
final List<Widget> widgets = [];
// 添加后台权限条目到最前端(仅在满足条件时)
final backgroundPermissionWidget = _buildBackgroundPermissionSection(isDarkMode);
if (backgroundPermissionWidget is! SizedBox) {
widgets.add(backgroundPermissionWidget);
if (groups.isNotEmpty) {
widgets.add(SizedBox(height: 20.h));
}
}
for (int i = 0; i < groups.length; i++) {
final group = groups[i];
@ -284,6 +293,285 @@ class PermissionsView extends GetView<PermissionsController> {
);
}
/// 构建后台权限条目
Widget _buildBackgroundPermissionSection(bool isDarkMode) {
// 检查是否为Android系统且语言为中文
if (!_shouldShowBackgroundPermissionTutorial()) {
return const SizedBox.shrink(); // 不满足条件时完全隐藏
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 组标题
Padding(
padding: EdgeInsets.only(left: 4.w, bottom: 8.h),
child: Text(
'后台权限'.tr, // 后台权限
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w500,
color: isDarkMode ? Colors.blue[400] : Colors.blue[600],
letterSpacing: 1,
),
),
),
// 权限项容器
Container(
decoration: BoxDecoration(
color: isDarkMode ? Colors.white.withOpacity(0.05) : Colors.white,
borderRadius: BorderRadius.circular(16.r),
boxShadow: [
BoxShadow(
color: isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(16.r),
child: BackdropFilter(
filter: isDarkMode
? ImageFilter.blur(sigmaX: 5, sigmaY: 5)
: ImageFilter.blur(sigmaX: 0, sigmaY: 0),
child: _buildBackgroundPermissionItem(isDarkMode),
),
),
),
],
);
}
/// 检查是否应该显示后台权限教程入口
/// 仅在Android系统且中文环境下显示
bool _shouldShowBackgroundPermissionTutorial() {
// 1. 检查是否为Android系统
if (!Platform.isAndroid) {
return false;
}
// 2. 检查设备语言区域是否为中文
final locale = Get.locale ?? Get.deviceLocale;
if (locale == null) {
return false;
}
// 检查语言代码是否为中文(zh)
return locale.languageCode == 'zh';
}
/// 构建后台权限条目内容
Widget _buildBackgroundPermissionItem(bool isDarkMode) {
return InkWell(
onTap: () {
_showBackgroundPermissionGuide();
},
child: Padding(
padding: EdgeInsets.all(16.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'后台运行'.tr, // 确保随时可以唤醒AI助手
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w500,
color: isDarkMode ? Colors.white : Colors.black87,
),
),
SizedBox(height: 4.h),
Text(
'设置后台运行权限,确保AI助手随时响应您的需求'.tr, // 设置后台运行权限,确保AI助手随时响应您的需求
style: TextStyle(
fontSize: 12.sp,
color: isDarkMode ? Colors.white70 : Colors.grey[600],
),
),
],
),
),
Icon(
Icons.arrow_forward_ios,
size: 16.sp,
color: isDarkMode ? Colors.white70 : Colors.grey[600],
),
],
),
),
);
}
// 显示后台权限设置指南
void _showBackgroundPermissionGuide() {
final isDarkMode = Theme.of(Get.context!).brightness == Brightness.dark;
Get.bottomSheet(
Container(
height: Get.height * 0.8,
decoration: BoxDecoration(
color: isDarkMode ? Colors.grey[900] : Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.r)),
),
child: Column(
children: [
// 顶部标题栏
Container(
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: isDarkMode
? Colors.grey[700]!
: Colors.grey.shade300)),
),
child: Row(
children: [
Text(
'后台运行权限设置'.tr,
style: TextStyle(
fontSize: 18.sp,
fontWeight: FontWeight.bold,
color: isDarkMode ? Colors.white : Colors.black,
),
),
Spacer(),
IconButton(
onPressed: () => Get.back(),
icon: Icon(
Icons.close,
color: isDarkMode ? Colors.white : Colors.black,
),
),
],
),
),
// 内容区域
Expanded(
child: SingleChildScrollView(
padding: EdgeInsets.all(16.w),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'为确保AI助手能够在后台正常运行,请根据您的手机品牌进行以下设置:'.tr,
style: TextStyle(
fontSize: 14.sp,
color: isDarkMode ? Colors.grey[300] : Colors.grey[600],
),
),
SizedBox(height: 20.h),
_buildBrandGuide(
'华为/荣耀',
[
'设置 → 应用 → 应用启动管理',
'找到Voitrans应用',
'关闭"自动管理"',
'开启"允许自启动"、"允许关联启动"、"允许后台活动"'
],
isDarkMode),
_buildBrandGuide(
'OPPO',
['设置 → 应用 → 自启动', '找到Voitrans应用', '打开"后台自启动"'],
isDarkMode),
_buildBrandGuide(
'vivo',
['i管家 → 应用管理 → 自启动 → 关联启动', '找到Voitrans应用', '允许"关联启动"'],
isDarkMode),
_buildBrandGuide(
'小米',
['设置 → 应用设置 → 应用管理', '找到Voitrans应用', '打开"自启动"'],
isDarkMode),
_buildBrandGuide(
'三星',
['长按Voitrans图标', '应用程序信息 → 电池', '打开"允许后台活动"'],
isDarkMode),
],
),
),
),
],
),
),
isScrollControlled: true,
);
}
// 构建品牌设置指南
Widget _buildBrandGuide(String brand, List<String> steps, bool isDarkMode) {
return Container(
margin: EdgeInsets.only(bottom: 20.h),
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
color: isDarkMode ? Colors.white.withOpacity(0.05) : Colors.grey[50],
borderRadius: BorderRadius.circular(12.r),
border: Border.all(
color: isDarkMode ? Colors.grey[700]! : Colors.grey.shade300),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
brand,
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.bold,
color: isDarkMode ? Colors.blue[400] : Colors.blue[600],
),
),
SizedBox(height: 8.h),
...steps.asMap().entries.map((entry) {
int index = entry.key;
String step = entry.value;
return Padding(
padding: EdgeInsets.only(bottom: 4.h),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 20.w,
height: 20.w,
decoration: BoxDecoration(
color: isDarkMode ? Colors.blue[400] : Colors.blue[600],
shape: BoxShape.circle,
),
child: Center(
child: Text(
'${index + 1}',
style: TextStyle(
color: Colors.white,
fontSize: 12.sp,
fontWeight: FontWeight.bold,
),
),
),
),
SizedBox(width: 8.w),
Expanded(
child: Text(
step,
style: TextStyle(
fontSize: 14.sp,
color: isDarkMode ? Colors.white : Colors.black87,
),
),
),
],
),
);
}).toList(),
],
),
);
}
void _handlePermissionToggle(
Permission permission,
PermissionStatus status,

2
pubspec.yaml

@ -1,7 +1,7 @@
name: voitrans
description: "Voitrans - AI Voice Assistant."
publish_to: "none"
version: 1.0.13+34
version: 1.0.14+37
environment:
sdk: ">=3.3.0 <4.0.0"

Loading…
Cancel
Save