基本完成APP的所有页面中的语言切换支持的开发和设计

This commit is contained in:
2026-04-24 15:24:43 +08:00
parent ba4519125e
commit 2e241cb9f5
26 changed files with 649 additions and 416 deletions

View File

@@ -5,6 +5,7 @@ import 'dart:math' as math;
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
import 'package:maibu_satabot_v2/features/home/presentation/widgets/common/commonFn.dart';
import 'package:syncfusion_flutter_gauges/gauges.dart';
import 'package:flutter/animation.dart';
@@ -135,14 +136,14 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
final currentDevice = deviceState.selectedDevice;
if (currentDevice != null) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("数据刷新成功!"), duration: Duration(seconds: 1)));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(AppLocalizations.of(context).translate('running_status.data_refresh_success')), duration: const Duration(seconds: 1)));
// 刷新后重置超时状态
if (_isDataTimeout) {
setState(() => _isDataTimeout = false);
}
_startDataTimeoutTimer();
} else {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("暂无设备,无法刷新"), duration: Duration(seconds: 1)));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(AppLocalizations.of(context).translate('running_status.no_device')), duration: const Duration(seconds: 1)));
}
}
@@ -273,7 +274,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
children: [
Icon(Icons.inbox_outlined, color: Colors.grey, size: 48),
SizedBox(height: 16),
Text('暂无数据', style: TextStyle(color: Colors.grey, fontSize: 16)),
Text(AppLocalizations.of(context).translate('running_status.no_data'), style: TextStyle(color: Colors.grey, fontSize: 16)),
],
),
);
@@ -314,9 +315,9 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_legendItem(color: const Color(0xFF3F51B5), label: "左轮"),
_legendItem(color: const Color(0xFF3F51B5), label: AppLocalizations.of(context).translate('running_status.left_wheel')),
const SizedBox(width: 24),
_legendItem(color: const Color(0xFF8BC34A), label: "右轮"),
_legendItem(color: const Color(0xFF8BC34A), label: AppLocalizations.of(context).translate('running_status.right_wheel')),
],
),
),
@@ -472,7 +473,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
child: Column(
children: [
_chartCard(
title: "电压 (V)",
title: AppLocalizations.of(context).translate('running_status.voltage') + " (V)",
isGaugeMode: _voltageGaugeMode,
onGaugeTap: () => setState(() => _voltageGaugeMode = true),
onChartTap: () => setState(() => _voltageGaugeMode = false),
@@ -481,7 +482,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
: SizedBox(
height: 180,
child: _styledLineChart(
title: "电压",
title: AppLocalizations.of(context).translate('running_status.voltage'),
lines: [_lineData(_voltageHistory, const Color(0xFF4CAF50))],
yAxisMax: 250,
yAxisMin: 0,
@@ -492,7 +493,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
_gap(),
_chartCard(
title: "芯片温度 (°C)",
title: AppLocalizations.of(context).translate('running_status.chip_temp') + " (°C)",
isGaugeMode: _chipTempGaugeMode,
onGaugeTap: () => setState(() => _chipTempGaugeMode = true),
onChartTap: () => setState(() => _chipTempGaugeMode = false),
@@ -501,7 +502,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
: SizedBox(
height: 180,
child: _styledLineChart(
title: "芯片温度",
title: AppLocalizations.of(context).translate('running_status.chip_temp'),
lines: [_lineData(_chipTempHistory, const Color(0xFF4CAF50))],
yAxisMax: 100,
yAxisMin: 0,
@@ -512,7 +513,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
_gap(),
_chartCard(
title: "割刀速度 (rpm)",
title: AppLocalizations.of(context).translate('running_status.knife_speed') + " (rpm)",
isGaugeMode: _knifeSpeedGaugeMode,
onGaugeTap: () => setState(() => _knifeSpeedGaugeMode = true),
onChartTap: () => setState(() => _knifeSpeedGaugeMode = false),
@@ -526,7 +527,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
: SizedBox(
height: 180,
child: _styledLineChart(
title: "割刀速度",
title: AppLocalizations.of(context).translate('running_status.knife_speed'),
lines: [_lineData(_knifeHistory, const Color(0xFF4CAF50))],
yAxisMax: 3000,
yAxisMin: -3000,
@@ -547,14 +548,14 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"左右轮测量速度对比 (rpm)",
AppLocalizations.of(context).translate('running_status.left_right_measure_speed') + " (rpm)",
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF1677FF)),
),
const SizedBox(height: 16),
SizedBox(
height: 180,
child: _styledLineChart(
title: "左右轮测量速度对比",
title: AppLocalizations.of(context).translate('running_status.left_right_measure_speed'),
lines: [_lineData(_leftMeasureHistory, const Color(0xFF3F51B5)), _lineData(_rightMeasureHistory, const Color(0xFF8BC34A))],
yAxisMax: 3000,
yAxisMin: -3000,
@@ -577,14 +578,14 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"左右轮目标速度对比 (rpm)",
AppLocalizations.of(context).translate('running_status.left_right_target_speed') + " (rpm)",
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF1677FF)),
),
const SizedBox(height: 16),
SizedBox(
height: 180,
child: _styledLineChart(
title: "左右轮目标速度对比",
title: AppLocalizations.of(context).translate('running_status.left_right_target_speed'),
lines: [_lineData(_leftTargetHistory, const Color(0xFF3F51B5)), _lineData(_rightTargetHistory, const Color(0xFF8BC34A))],
yAxisMax: 3000,
yAxisMin: -3000,
@@ -607,14 +608,14 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"电流对比 (A)",
AppLocalizations.of(context).translate('running_status.current_compare') + " (A)",
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF1677FF)),
),
const SizedBox(height: 16),
SizedBox(
height: 180,
child: _styledLineChart(
title: "电流对比",
title: AppLocalizations.of(context).translate('running_status.current_compare'),
lines: [_lineData(_leftCurrentHistory, const Color(0xFF3F51B5)), _lineData(_rightCurrentHistory, const Color(0xFF8BC34A))],
yAxisMax: 100,
yAxisMin: 0,
@@ -637,14 +638,14 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"电机温度对比 (°C)",
AppLocalizations.of(context).translate('running_status.motor_temp_compare') + " (°C)",
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF1677FF)),
),
const SizedBox(height: 16),
SizedBox(
height: 180,
child: _styledLineChart(
title: "电机温度对比",
title: AppLocalizations.of(context).translate('running_status.motor_temp_compare'),
lines: [_lineData(_leftTempHistory, const Color(0xFF3F51B5)), _lineData(_rightTempHistory, const Color(0xFF8BC34A))],
yAxisMax: 100,
yAxisMin: 0,
@@ -667,7 +668,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"航向角 (°)",
AppLocalizations.of(context).translate('running_status.heading_angle_chart') + " (°)",
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF1677FF)),
),
const SizedBox(height: 16),
@@ -705,9 +706,9 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.symmetric(vertical: 12),
child: Text("电机参数", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Text(AppLocalizations.of(context).translate('running_status.motor_params'), style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
),
Table(
border: TableBorder.all(color: const Color(0xFFE5E5E5)),
@@ -715,32 +716,32 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
children: [
TableRow(
decoration: const BoxDecoration(color: Color(0xFFF5F5F5)),
children: [const SizedBox(), _buildTableCell("左轮", isHeader: true), _buildTableCell("右轮", isHeader: true)],
children: [const SizedBox(), _buildTableCell(AppLocalizations.of(context).translate('running_status.left_wheel'), isHeader: true), _buildTableCell(AppLocalizations.of(context).translate('running_status.right_wheel'), isHeader: true)],
),
TableRow(
children: [
_buildTableCell("目标速度\n(rpm)"),
_buildTableCell(AppLocalizations.of(context).translate('running_status.target_speed') + "\n(rpm)"),
_buildTableCell(status.leftTargetSpeed.toStringAsFixed(2)),
_buildTableCell(status.rightTargetSpeed.toStringAsFixed(2)),
],
),
TableRow(
children: [
_buildTableCell("测量速度\n(rpm)"),
_buildTableCell(AppLocalizations.of(context).translate('running_status.measure_speed') + "\n(rpm)"),
_buildTableCell(status.leftMeasureSpeed.toStringAsFixed(2)),
_buildTableCell(status.rightMeasureSpeed.toStringAsFixed(2)),
],
),
TableRow(
children: [
_buildTableCell("电流(A)"),
_buildTableCell(AppLocalizations.of(context).translate('running_status.current') + "(A)"),
_buildTableCell(status.leftCurrent.toStringAsFixed(2)),
_buildTableCell(status.rightCurrent.toStringAsFixed(2)),
],
),
TableRow(
children: [
_buildTableCell("电机温度(°C)"),
_buildTableCell(AppLocalizations.of(context).translate('running_status.motor_temp') + "(°C)"),
_buildTableCell(status.leftMotorTemp.toStringAsFixed(2)),
_buildTableCell(status.rightMotorTemp.toStringAsFixed(2)),
],
@@ -756,9 +757,9 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.symmetric(vertical: 12),
child: Text("其他参数", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Text(AppLocalizations.of(context).translate('running_status.other_params'), style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
),
Table(
border: TableBorder.all(color: const Color(0xFFE5E5E5)),
@@ -766,17 +767,17 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
children: [
TableRow(
decoration: const BoxDecoration(color: Color(0xFFF5F5F5)),
children: [_buildTableCell("名称", isHeader: true), _buildTableCell("数值", isHeader: true)],
children: [_buildTableCell(AppLocalizations.of(context).translate('running_status.name'), isHeader: true), _buildTableCell(AppLocalizations.of(context).translate('running_status.value'), isHeader: true)],
),
TableRow(children: [_buildTableCell("俯仰角(°)"), _buildTableCell(status.pitch.toStringAsFixed(2))]),
TableRow(children: [_buildTableCell("翻滚角(°)"), _buildTableCell(status.roll.toStringAsFixed(2))]),
TableRow(children: [_buildTableCell("航向角(°)"), _buildTableCell(status.yaw.toStringAsFixed(2))]),
TableRow(children: [_buildTableCell("电量(%)"), _buildTableCell(status.battery)]),
TableRow(children: [_buildTableCell("芯片温度(°C)"), _buildTableCell(status.chipTemp.toStringAsFixed(2))]),
TableRow(children: [_buildTableCell("割刀速度(rpm)"), _buildTableCell(status.knifeCuttingSpeed)]),
TableRow(children: [_buildTableCell("控制模式"), _buildTableCell(LocationUtils.parseControlMode(int.parse(status.controlMode)))]),
TableRow(children: [_buildTableCell("经度(°)"), _buildTableCell(status.longitude.toStringAsFixed(6))]),
TableRow(children: [_buildTableCell("纬度(°)"), _buildTableCell(status.latitude.toStringAsFixed(6))]),
TableRow(children: [_buildTableCell(AppLocalizations.of(context).translate('running_status.pitch_angle') + "(°)"), _buildTableCell(status.pitch.toStringAsFixed(2))]),
TableRow(children: [_buildTableCell(AppLocalizations.of(context).translate('running_status.roll_angle') + "(°)"), _buildTableCell(status.roll.toStringAsFixed(2))]),
TableRow(children: [_buildTableCell(AppLocalizations.of(context).translate('running_status.heading_angle') + "(°)"), _buildTableCell(status.yaw.toStringAsFixed(2))]),
TableRow(children: [_buildTableCell(AppLocalizations.of(context).translate('running_status.battery') + "(%)"), _buildTableCell(status.battery)]),
TableRow(children: [_buildTableCell(AppLocalizations.of(context).translate('running_status.chip_temp') + "(°C)"), _buildTableCell(status.chipTemp.toStringAsFixed(2))]),
TableRow(children: [_buildTableCell(AppLocalizations.of(context).translate('running_status.knife_speed') + "(rpm)"), _buildTableCell(status.knifeCuttingSpeed)]),
TableRow(children: [_buildTableCell(AppLocalizations.of(context).translate('running_status.control_mode')), _buildTableCell(AppLocalizations.of(context).translate(_getControlModeKey(int.parse(status.controlMode))))]),
TableRow(children: [_buildTableCell(AppLocalizations.of(context).translate('running_status.longitude') + "(°)"), _buildTableCell(status.longitude.toStringAsFixed(6))]),
TableRow(children: [_buildTableCell(AppLocalizations.of(context).translate('running_status.latitude') + "(°)"), _buildTableCell(status.latitude.toStringAsFixed(6))]),
],
),
],
@@ -823,6 +824,34 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
);
}
// 辅助方法:根据定位质量值返回翻译键
String _getLocationQualityKey(int qualValue) {
switch (qualValue) {
case 0:
return 'running_status.invalid';
case 1:
return 'common.unknown'; // GPS单点定位 - 使用通用未知
case 2:
return 'common.unknown'; // DGPS - 使用通用未知
case 4:
return 'running_status.valid'; // RTK固定解 - 视为有效
case 5:
return 'running_status.valid'; // RTK浮点解 - 视为有效
default:
return 'common.unknown';
}
}
// 辅助方法:根据控制模式值返回翻译键
String _getControlModeKey(int modeValue) {
switch (modeValue) {
case 3:
return 'running_status.remote_control';
default:
return 'running_status.local_control';
}
}
@override
Widget build(BuildContext context) {
final deviceState = context.read<DevicesCubit>().state;
@@ -851,14 +880,14 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
String headingStatus = _isDataTimeout ? "--" : "--";
if (!_isDataTimeout && state is DeviceStatusUpdated) {
headingStatus = state.status.headingStatus == 0 ? '未初始化' : '已初始化';
headingStatus = state.status.headingStatus == 0 ? AppLocalizations.of(context).translate('running_status.not_initialized') : AppLocalizations.of(context).translate('running_status.initialized');
int qualValue = 0;
try {
qualValue = int.parse(state.status.qual.toString());
} catch (e) {
qualValue = 0;
}
qual = LocationUtils.parseLocationQuality(qualValue);
qual = AppLocalizations.of(context).translate(_getLocationQualityKey(qualValue));
satelliteCnt = state.status.satelliteCnt.toString();
// 收到新数据,重置超时计时器和状态
@@ -881,12 +910,12 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
children: [
Expanded(
flex: 3,
child: Text("航向角状态:$headingStatus", style: const TextStyle(fontSize: 12), maxLines: 1, overflow: TextOverflow.ellipsis),
child: Text(AppLocalizations.of(context).translate('running_status.heading_status') + ":$headingStatus", style: const TextStyle(fontSize: 12), maxLines: 1, overflow: TextOverflow.ellipsis),
),
Expanded(
flex: 4,
child: Text(
"定位质量:$qual",
AppLocalizations.of(context).translate('running_status.position_quality') + ":$qual",
style: const TextStyle(fontSize: 12),
maxLines: 1,
overflow: TextOverflow.ellipsis,
@@ -896,7 +925,7 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
Expanded(
flex: 2,
child: Text(
"卫星数:$satelliteCnt",
AppLocalizations.of(context).translate('running_status.satellite_count') + ":$satelliteCnt",
style: const TextStyle(fontSize: 12),
maxLines: 1,
overflow: TextOverflow.ellipsis,
@@ -922,12 +951,12 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
children: [
GestureDetector(
onTap: () => setState(() => _isCardView = true),
child: _buildTab("卡片", isActive: _isCardView),
child: _buildTab(AppLocalizations.of(context).translate('running_status.card'), isActive: _isCardView),
),
const SizedBox(width: 24),
GestureDetector(
onTap: () => setState(() => _isCardView = false),
child: _buildTab("图表", isActive: !_isCardView),
child: _buildTab(AppLocalizations.of(context).translate('running_status.chart'), isActive: !_isCardView),
),
],
),
@@ -988,9 +1017,9 @@ class _RunningStatusPageState extends State<RunningStatusPage> with WidgetsBindi
backgroundColor: const Color(0xFF1677FF),
elevation: 4, // 增加阴影,提升层次感
centerTitle: true,
title: const Text(
"设备数据监控",
style: TextStyle(
title: Text(
AppLocalizations.of(context).translate('running_status.title'),
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,