多语言切换+首次设置语言

This commit is contained in:
2026-10-12 14:21:09 +08:00
parent dc006c2935
commit 9671798f29
22 changed files with 572 additions and 274 deletions

View File

@@ -21,76 +21,46 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
List<String> _selectedImages = [];
static const _feedbackTypes = [
{'icon': Icons.lightbulb_outline, 'label': '功能建议'},
{'icon': Icons.bug_report_outlined, 'label': 'Bug报告'},
{'icon': Icons.sentiment_dissatisfied_outlined, 'label': '体验问题'},
{'icon': Icons.more_horiz, 'label': '其他'},
{'icon': Icons.lightbulb_outline, 'label': 'type_feature'},
{'icon': Icons.bug_report_outlined, 'label': 'type_bug'},
{'icon': Icons.sentiment_dissatisfied_outlined, 'label': 'type_experience'},
{'icon': Icons.more_horiz, 'label': 'type_other'},
];
static const _faqList = [
{
'category': '设备绑定',
'category': 'cat_bind',
'questions': [
{
'q': '扫码绑定失败怎么办?',
'a': '请检查设备是否已开机并处于待绑定状态,确保手机蓝牙已开启且网络正常。如仍无法绑定,请尝试重启设备后重新扫码。'
},
{
'q': '搜不到设备蓝牙信号?',
'a': '请确认设备已开机且蓝牙指示灯正常闪烁。尝试靠近设备(1米以内)后重新搜索。如多个设备同时绑定,请逐一操作。'
},
{'q': 'q_bind_fail', 'a': 'a_bind_fail'},
{'q': 'q_bt_notfound', 'a': 'a_bt_notfound'},
]
},
{
'category': '路径规划',
'category': 'cat_path',
'questions': [
{
'q': '无法生成路径?',
'a': '请确保已绘制完整的作业区域(至少3个打点),并检查GPS信号是否良好。如果使用自动规划模式,请确认区域边界没有自相交。'
},
{
'q': '地图不显示或定位偏移?',
'a': '请检查手机GPS是否已开启,并授权App位置权限。在室内或信号较弱的区域可能出现定位偏移,建议到开阔区域使用。'
},
{'q': 'q_path_none', 'a': 'a_path_none'},
{'q': 'q_map_issue', 'a': 'a_map_issue'},
]
},
{
'category': '远程控制',
'category': 'cat_remote',
'questions': [
{
'q': '远程视频卡顿/连接超时?',
'a': '请检查手机和设备的网络连接是否稳定。建议在4G/Wi-Fi信号良好的环境下使用远程控制功能。如持续卡顿,可尝试降低视频分辨率。'
},
{
'q': '急停功能怎么使用?',
'a': '在远程控制页面,点击屏幕中央红色急停按钮即可立即停止设备运行。急停后需手动解除才能恢复操作。'
},
{'q': 'q_video_stutter', 'a': 'a_video_stutter'},
{'q': 'q_estop', 'a': 'a_estop'},
]
},
{
'category': '工单系统',
'category': 'cat_order',
'questions': [
{
'q': '如何提交工单?',
'a': '在「工单」页面点击右下角「新建工单」按钮,选择工单类型,填写问题描述并上传相关图片后提交即可。'
},
{
'q': '工单状态怎么看?',
'a': '在「工单」页面可查看所有已提交的工单及其当前状态(待处理/处理中/已完成)。点击具体工单可查看详情和回复。'
},
{'q': 'q_order_submit', 'a': 'a_order_submit'},
{'q': 'q_order_status', 'a': 'a_order_status'},
]
},
{
'category': '账号问题',
'category': 'cat_account',
'questions': [
{
'q': '忘记密码怎么办?',
'a': '在登录页面点击「忘记密码」,通过注册手机号验证后即可重置密码。'
},
{
'q': '换设备登录需要重新绑定?',
'a': '更换手机登录同一账号后,设备绑定关系不会丢失。但需要在新设备上重新搜索和连接设备。'
},
{'q': 'q_pwd_forget', 'a': 'a_pwd_forget'},
{'q': 'q_rebind_device', 'a': 'a_rebind_device'},
]
},
];
@@ -139,9 +109,9 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
unselectedLabelColor: context.appColors.textTertiary,
indicatorColor: const Color(0xFF165DFF),
indicatorSize: TabBarIndicatorSize.label,
tabs: const [
Tab(text: '常见问题'),
Tab(text: '意见反馈'),
tabs: [
Tab(text: AppLocalizations.of(context).translate('help_feedback.tab_faq')),
Tab(text: AppLocalizations.of(context).translate('help_feedback.tab_feedback')),
],
),
),
@@ -177,7 +147,7 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 8),
child: Text(
categoryData['category'] as String,
AppLocalizations.of(context).translate("help_feedback.${categoryData['category']}"),
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
@@ -203,8 +173,8 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
final item = entry.value as Map<String, dynamic>;
final isLast = index == questions.length - 1;
return _buildFAQItem(
item['q'] as String,
item['a'] as String,
AppLocalizations.of(context).translate("help_feedback.${item['q']}"),
AppLocalizations.of(context).translate("help_feedback.${item['a']}"),
isLast,
);
}).toList(),
@@ -275,7 +245,7 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'联系客服',
AppLocalizations.of(context).translate('help_feedback.contact_title'),
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
@@ -285,15 +255,15 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
const SizedBox(height: 16),
_buildContactItem(
Icons.phone_outlined,
'客服热线',
AppLocalizations.of(context).translate('help_feedback.hotline'),
'400-000-0000',
onTap: () => _showPhoneDialog('400-000-0000'),
),
const Divider(height: 24),
_buildContactItem(
Icons.qr_code_2,
'企业微信',
'扫码添加客服微信',
AppLocalizations.of(context).translate('help_feedback.wechat_work'),
AppLocalizations.of(context).translate('help_feedback.wechat_hint'),
onTap: () => debugPrint('显示企业微信二维码'),
),
],
@@ -350,7 +320,7 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
children: [
// 反馈类型
_buildSectionCard(
title: '反馈类型',
title: AppLocalizations.of(context).translate('help_feedback.feedback_type'),
child: Wrap(
spacing: 8,
runSpacing: 8,
@@ -389,7 +359,7 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
),
const SizedBox(width: 6),
Text(
type['label'] as String,
AppLocalizations.of(context).translate("help_feedback.${type['label']}"),
style: TextStyle(
fontSize: 13,
color: isSelected
@@ -410,13 +380,13 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
// 问题描述
_buildSectionCard(
title: '问题描述',
title: AppLocalizations.of(context).translate('help_feedback.problem_desc'),
child: TextField(
controller: _feedbackController,
maxLines: 5,
maxLength: 500,
decoration: InputDecoration(
hintText: '请详细描述您遇到的问题或建议...',
hintText: AppLocalizations.of(context).translate('help_feedback.problem_hint'),
hintStyle: TextStyle(
fontSize: 14,
color: context.appColors.textTertiary,
@@ -446,7 +416,8 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
// 添加截图
_buildSectionCard(
title: '添加截图 (${_selectedImages.length}/6)',
title:
'${AppLocalizations.of(context).translate('help_feedback.add_screenshot')} (${_selectedImages.length}/6)',
child: Wrap(
spacing: 8,
runSpacing: 8,
@@ -462,11 +433,11 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
// 联系方式
_buildSectionCard(
title: '联系方式(选填)',
title: AppLocalizations.of(context).translate('help_feedback.contact_label'),
child: TextField(
controller: _contactController,
decoration: InputDecoration(
hintText: '手机号/微信号,方便我们回访',
hintText: AppLocalizations.of(context).translate('help_feedback.contact_hint'),
hintStyle: TextStyle(
fontSize: 14,
color: context.appColors.textTertiary,
@@ -516,9 +487,9 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
borderRadius: BorderRadius.circular(12),
),
),
child: const Text(
'提交反馈',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
child: Text(
AppLocalizations.of(context).translate('help_feedback.submit_feedback'),
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
),
),
@@ -630,7 +601,7 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
),
const SizedBox(height: 4),
Text(
'添加截图',
AppLocalizations.of(context).translate('help_feedback.add_screenshot'),
style: TextStyle(
fontSize: 11,
color: context.appColors.textTertiary,
@@ -645,10 +616,11 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
// ==================== 交互方法 ====================
void _showPhoneDialog(String phoneNumber) {
final loc = AppLocalizations.of(context);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('客服热线'),
title: Text(loc.translate('help_feedback.hotline')),
content: SelectableText(
phoneNumber,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
@@ -656,17 +628,17 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('关闭'),
child: Text(loc.translate('help_feedback.close')),
),
TextButton(
onPressed: () {
Clipboard.setData(ClipboardData(text: phoneNumber));
Navigator.pop(context);
ScaffoldMessenger.of(this.context).showSnackBar(
const SnackBar(content: Text('号码已复制')),
SnackBar(content: Text(loc.translate('help_feedback.number_copied'))),
);
},
child: const Text('复制号码'),
child: Text(loc.translate('help_feedback.copy_number')),
),
],
),
@@ -684,9 +656,9 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
void _submitFeedback() {
if (_feedbackController.text.trim().isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('请输入问题描述'),
backgroundColor: Color(0xFFF53F3F),
SnackBar(
content: Text(AppLocalizations.of(context).translate('help_feedback.please_input_desc')),
backgroundColor: const Color(0xFFF53F3F),
),
);
return;
@@ -700,7 +672,7 @@ class _HelpFeedbackPageState extends State<HelpFeedbackPage>
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('反馈已提交,感谢您的支持!'),
content: Text(AppLocalizations.of(context).translate('help_feedback.submit_success')),
backgroundColor: context.appColors.success,
),
);

View File

@@ -5,6 +5,7 @@ import 'package:get_it/get_it.dart';
import 'package:go_router/go_router.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
import 'package:maibu_satabot_v2/core/localization/locale_cubit.dart';
import 'package:maibu_satabot_v2/components/language_selection_dialog.dart';
import 'package:maibu_satabot_v2/core/router/route_paths.dart';
import 'package:maibu_satabot_v2/core/theme/AppTheme.dart';
import 'package:maibu_satabot_v2/core/storage/user_storage.dart';
@@ -196,7 +197,10 @@ class _SystemSettingsPageState extends State<SystemSettingsPage> {
children: [
Expanded(
child: Text(
tab.name,
// 按当前语言显示 Tab 名
Localizations.localeOf(context).languageCode == 'en'
? tab.nameEn
: tab.name,
style: TextStyle(
fontSize: 14,
color: context.appColors.textPrimary,
@@ -251,29 +255,40 @@ class _SystemSettingsPageState extends State<SystemSettingsPage> {
color: context.appColors.textPrimary,
),
),
const SizedBox(height: 16),
const SizedBox(height: 12),
// 统一复用语言选择弹窗,只需选一个入口维护语言列表
BlocBuilder<LocaleCubit, Locale>(
builder: (context, locale) {
return Column(
children: [
_buildLanguageOption(
AppLocalizations.of(context).translate('my.chinese'),
'zh',
locale.languageCode == 'zh',
() => context.read<LocaleCubit>().setLocale(
const Locale('zh', 'CN'),
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => showDialog(
context: context,
builder: (_) => const LanguageSelectionDialog(mandatory: false),
),
child: Row(
children: [
Icon(
Icons.language,
size: 20,
color: context.appColors.textSecondary,
),
),
const SizedBox(height: 12),
_buildLanguageOption(
AppLocalizations.of(context).translate('my.english'),
'en',
locale.languageCode == 'en',
() => context.read<LocaleCubit>().setLocale(
const Locale('en', 'US'),
const SizedBox(width: 8),
Expanded(
child: Text(
AppLanguages.instance.nameOf(locale),
style: TextStyle(
fontSize: 14,
color: context.appColors.textPrimary,
),
),
),
),
],
Icon(
Icons.arrow_forward_ios,
size: 16,
color: context.appColors.textTertiary,
),
],
),
);
},
),
@@ -282,54 +297,6 @@ class _SystemSettingsPageState extends State<SystemSettingsPage> {
);
}
Widget _buildLanguageOption(
String label,
String code,
bool isSelected,
VoidCallback onTap,
) {
return GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: isSelected
? const Color(0xFF165DFF).withOpacity(0.1)
: Colors.transparent,
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: isSelected
? const Color(0xFF165DFF)
: context.appColors.divider,
width: 1,
),
),
child: Row(
children: [
Expanded(
child: Text(
label,
style: TextStyle(
fontSize: 14,
color: isSelected
? const Color(0xFF165DFF)
: context.appColors.textPrimary,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
),
),
),
if (isSelected)
const Icon(
Icons.check_circle,
color: Color(0xFF165DFF),
size: 20,
),
],
),
),
);
}
/// 版本更新
Widget _buildUpdateSection() {
return Container(