基本完成APP的所有页面中的语言切换支持的开发和设计
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
class ManualPage extends StatefulWidget {
|
||||
const ManualPage({super.key});
|
||||
@@ -13,49 +14,69 @@ class _ManualPageState extends State<ManualPage> {
|
||||
bool showMenu = true;
|
||||
String currentType = '';
|
||||
|
||||
final List<String> menuTitles = const ['安全警示及使用注意事项', '机器使用说明', '保养与维修', '故障处置', '本商品搬运的要领', '关于三包与售后服务'];
|
||||
|
||||
final List<List<Map<String, dynamic>>> subMenus = [
|
||||
[
|
||||
{'title': '特别警告', 'type': 'alert'},
|
||||
{'title': '关于本产品的警告标签说明', 'type': 'alertinstruction'},
|
||||
{'title': '安全操作须知', 'type': 'safety'},
|
||||
{'title': '安全驾驶·安全作业须知', 'type': 'safetywork'},
|
||||
],
|
||||
[
|
||||
{'title': '发动前的准备', 'type': 'prepare'},
|
||||
{'title': '启动方法', 'type': 'startmethod'},
|
||||
{'title': '割草方法', 'type': 'work'},
|
||||
{'title': '停车方法', 'type': 'stop'},
|
||||
{'title': '遥控器使用', 'type': 'controluse'},
|
||||
],
|
||||
[
|
||||
{'title': '定期检查表', 'type': 'check1'},
|
||||
{'title': '行走部分及割草部分的检查', 'type': 'check2'},
|
||||
{'title': '加油、加水以及上润滑脂、润滑油一览表', 'type': 'supply'},
|
||||
{'title': '消耗零件(更换零件)一览表', 'type': 'check4'},
|
||||
{'title': '发动机', 'type': 'check5'},
|
||||
{'title': '行走装置', 'type': 'check6'},
|
||||
{'title': '使用后的维修', 'type': 'check7'},
|
||||
],
|
||||
[
|
||||
{'title': '问题诊断表', 'type': 'breakdown1'},
|
||||
],
|
||||
[
|
||||
{'title': '搬运要领', 'type': 'starpoint'},
|
||||
],
|
||||
[
|
||||
{'title': '关于三包', 'type': 'about1'},
|
||||
{'title': '关于售后服务', 'type': 'about2'},
|
||||
{'title': '关于零件的补给年限(期间)', 'type': 'supplyyear'},
|
||||
],
|
||||
];
|
||||
late List<String> menuTitles;
|
||||
late List<List<Map<String, dynamic>>> subMenus;
|
||||
|
||||
void _initLocalizedMenus() {
|
||||
final loc = AppLocalizations.of(context);
|
||||
menuTitles = [
|
||||
loc.translate('manual.menu_titles.0'),
|
||||
loc.translate('manual.menu_titles.1'),
|
||||
loc.translate('manual.menu_titles.2'),
|
||||
loc.translate('manual.menu_titles.3'),
|
||||
loc.translate('manual.menu_titles.4'),
|
||||
loc.translate('manual.menu_titles.5'),
|
||||
];
|
||||
|
||||
subMenus = [
|
||||
[
|
||||
{'title': loc.translate('manual.submenus.alert'), 'type': 'alert'},
|
||||
{'title': loc.translate('manual.submenus.alertinstruction'), 'type': 'alertinstruction'},
|
||||
{'title': loc.translate('manual.submenus.safety'), 'type': 'safety'},
|
||||
{'title': loc.translate('manual.submenus.safetywork'), 'type': 'safetywork'},
|
||||
],
|
||||
[
|
||||
{'title': loc.translate('manual.submenus.prepare'), 'type': 'prepare'},
|
||||
{'title': loc.translate('manual.submenus.startmethod'), 'type': 'startmethod'},
|
||||
{'title': loc.translate('manual.submenus.work'), 'type': 'work'},
|
||||
{'title': loc.translate('manual.submenus.stop'), 'type': 'stop'},
|
||||
{'title': loc.translate('manual.submenus.controluse'), 'type': 'controluse'},
|
||||
],
|
||||
[
|
||||
{'title': loc.translate('manual.submenus.check1'), 'type': 'check1'},
|
||||
{'title': loc.translate('manual.submenus.check2'), 'type': 'check2'},
|
||||
{'title': loc.translate('manual.submenus.supply'), 'type': 'supply'},
|
||||
{'title': loc.translate('manual.submenus.check4'), 'type': 'check4'},
|
||||
{'title': loc.translate('manual.submenus.check5'), 'type': 'check5'},
|
||||
{'title': loc.translate('manual.submenus.check6'), 'type': 'check6'},
|
||||
{'title': loc.translate('manual.submenus.check7'), 'type': 'check7'},
|
||||
],
|
||||
[
|
||||
{'title': loc.translate('manual.submenus.breakdown1'), 'type': 'breakdown1'},
|
||||
],
|
||||
[
|
||||
{'title': loc.translate('manual.submenus.starpoint'), 'type': 'starpoint'},
|
||||
],
|
||||
[
|
||||
{'title': loc.translate('manual.submenus.about1'), 'type': 'about1'},
|
||||
{'title': loc.translate('manual.submenus.about2'), 'type': 'about2'},
|
||||
{'title': loc.translate('manual.submenus.supplyyear'), 'type': 'supplyyear'},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
late List<bool> expandedList;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// menuTitles 和 subMenus 在 build 时初始化
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_initLocalizedMenus();
|
||||
expandedList = List.filled(menuTitles.length, false);
|
||||
}
|
||||
|
||||
@@ -83,6 +104,7 @@ class _ManualPageState extends State<ManualPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_initLocalizedMenus(); // 确保每次build时更新语言
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF7F8FA),
|
||||
appBar: AppBar(
|
||||
@@ -90,7 +112,7 @@ class _ManualPageState extends State<ManualPage> {
|
||||
elevation: 1,
|
||||
centerTitle: true,
|
||||
title: Text(
|
||||
showMenu ? '使用说明' : _getCurrentTitle(),
|
||||
showMenu ? AppLocalizations.of(context).translate('manual.title') : _getCurrentTitle(),
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF2A3A55)),
|
||||
),
|
||||
leading: IconButton(
|
||||
@@ -188,10 +210,11 @@ class _ManualPageState extends State<ManualPage> {
|
||||
}
|
||||
|
||||
Widget _buildContent() {
|
||||
return SingleChildScrollView(padding: const EdgeInsets.all(16), physics: const BouncingScrollPhysics(), child: _getContentWidget());
|
||||
final loc = AppLocalizations.of(context);
|
||||
return SingleChildScrollView(padding: const EdgeInsets.all(16), physics: const BouncingScrollPhysics(), child: _getContentWidget(loc));
|
||||
}
|
||||
|
||||
Widget _getContentWidget() {
|
||||
Widget _getContentWidget(AppLocalizations loc) {
|
||||
if (currentType == 'supply') {
|
||||
return _buildSupplyTable();
|
||||
} else if (currentType == 'breakdown1') {
|
||||
@@ -211,23 +234,23 @@ class _ManualPageState extends State<ManualPage> {
|
||||
const SizedBox(height: 16),
|
||||
_buildDiagnosticTable1(),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
"发电机",
|
||||
style: TextStyle(fontSize: 17, fontWeight: FontWeight.bold, color: Color(0xFF2A3A55)),
|
||||
Text(
|
||||
loc.translate('manual.tables.generator'),
|
||||
style: const TextStyle(fontSize: 17, fontWeight: FontWeight.bold, color: Color(0xFF2A3A55)),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildDiagnosticTable2(),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
"行走装置",
|
||||
style: TextStyle(fontSize: 17, fontWeight: FontWeight.bold, color: Color(0xFF2A3A55)),
|
||||
Text(
|
||||
loc.translate('manual.tables.walking_device'),
|
||||
style: const TextStyle(fontSize: 17, fontWeight: FontWeight.bold, color: Color(0xFF2A3A55)),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildDiagnosticTable3(),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
"割草装置",
|
||||
style: TextStyle(fontSize: 17, fontWeight: FontWeight.bold, color: Color(0xFF2A3A55)),
|
||||
Text(
|
||||
loc.translate('manual.tables.mowing_device'),
|
||||
style: const TextStyle(fontSize: 17, fontWeight: FontWeight.bold, color: Color(0xFF2A3A55)),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildDiagnosticTable4(),
|
||||
@@ -239,7 +262,10 @@ class _ManualPageState extends State<ManualPage> {
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(12)),
|
||||
child: const Text('本商品单个零件的提供年限为停止生产后三年。', style: TextStyle(fontSize: 16, color: Color(0xFF333333))),
|
||||
child: Text(loc.translate('manual.submenus.supplyyear') == '关于零件的补给年限(期间)'
|
||||
? '本商品单个零件的提供年限为停止生产后三年。'
|
||||
: 'The supply period for individual parts of this product is three years after production cessation.',
|
||||
style: const TextStyle(fontSize: 16, color: Color(0xFF333333))),
|
||||
);
|
||||
} else if (markdownMap.containsKey(currentType)) {
|
||||
return Container(
|
||||
@@ -269,7 +295,7 @@ class _ManualPageState extends State<ManualPage> {
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(12)),
|
||||
child: const Text("暂无内容", style: TextStyle(fontSize: 16, color: Color(0xFF8A98AC))),
|
||||
child: Text(AppLocalizations.of(context).translate('manual.no_content'), style: const TextStyle(fontSize: 16, color: Color(0xFF8A98AC))),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -283,19 +309,20 @@ class _ManualPageState extends State<ManualPage> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return '详情';
|
||||
return AppLocalizations.of(context).translate('manual.detail');
|
||||
}
|
||||
|
||||
Widget _buildSupplyTable() {
|
||||
final loc = AppLocalizations.of(context);
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(12)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'加油、加水以及上润滑脂、润滑油一览表',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF2A3A55)),
|
||||
Text(
|
||||
loc.translate('manual.tables.supply_title'),
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF2A3A55)),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SingleChildScrollView(
|
||||
@@ -307,10 +334,10 @@ class _ManualPageState extends State<ManualPage> {
|
||||
TableRow(
|
||||
decoration: const BoxDecoration(color: Color(0xFFF7F8FA)),
|
||||
children: [
|
||||
TableCell(child: _tableCellText('项目', isHeader: true)),
|
||||
TableCell(child: _tableCellText('补给(交换)的时期', isHeader: true)),
|
||||
TableCell(child: _tableCellText('推荐品种', isHeader: true)),
|
||||
TableCell(child: _tableCellText('容量', isHeader: true)),
|
||||
TableCell(child: _tableCellText(loc.translate('manual.tables.item'), isHeader: true)),
|
||||
TableCell(child: _tableCellText(loc.translate('manual.tables.period'), isHeader: true)),
|
||||
TableCell(child: _tableCellText(loc.translate('manual.tables.recommend'), isHeader: true)),
|
||||
TableCell(child: _tableCellText(loc.translate('manual.tables.capacity'), isHeader: true)),
|
||||
],
|
||||
),
|
||||
_tableRowSimple(['燃料', '随时', '汽车用91号以上无铅汽油或乙醇含量不超过10%的无铅汽油(E10)', '10L']),
|
||||
@@ -443,9 +470,14 @@ class _ManualPageState extends State<ManualPage> {
|
||||
}
|
||||
|
||||
TableRow _tableHeader() {
|
||||
final loc = AppLocalizations.of(context);
|
||||
return TableRow(
|
||||
decoration: const BoxDecoration(color: Color(0xFFF7F8FA)),
|
||||
children: [_tableCellText("问题现象说明", isHeader: true), _tableCellText("原因", isHeader: true), _tableCellText("处理", isHeader: true)],
|
||||
children: [
|
||||
_tableCellText(loc.translate('manual.tables.problem'), isHeader: true),
|
||||
_tableCellText(loc.translate('manual.tables.reason'), isHeader: true),
|
||||
_tableCellText(loc.translate('manual.tables.solution'), isHeader: true)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user