feat(device): 添加USB设备通信支持和程序参数优化

- 在AndroidManifest.xml中添加USB Host权限和设备过滤器配置
- 新增设备控制国际化词条包括速度档位、吹气时间等
- 重构数据库结构将速度相关字段统一为档位数值存储
- 添加通用KV存储方法用于settings表数据读写
- 优化首页导航实现tab间跳转和状态保持功能
- 更新程序详情页面布局和参数表单界面
- 移除模拟运行器相关测试代码
- 添加USB串口通信依赖包usb_serial
This commit is contained in:
Developer
2026-06-04 15:13:36 +08:00
parent 67e2c7c76c
commit d53c41c300
24 changed files with 795 additions and 635 deletions

View File

@@ -194,7 +194,7 @@ class RunStatusMonitor extends ConsumerWidget {
if (step.mixTime > 0)
_buildParamRow(
l10n?.speed ?? '转速',
'${step.mixSpeed}',
'${step.speed}',
),
if (step.magnetTime > 0)
_buildParamRow(

View File

@@ -4,10 +4,11 @@ import '../../../core/localization/app_localizations.dart';
import '../../../core/theme/app_theme.dart';
import '../../../shared/widgets/common_button.dart';
import '../../device/providers/run_state_provider.dart';
import '../../programs/models/program.dart';
import '../../programs/providers/programs_provider.dart';
/// 运行控制面板 - 暗色工业风格
/// 显示当前程序信息、瓷套棒状态和运行控制按钮
/// 显示当前程序信息和运行控制按钮
class RunningControlPanel extends ConsumerWidget {
const RunningControlPanel({super.key});
@@ -96,40 +97,6 @@ class RunningControlPanel extends ConsumerWidget {
const SizedBox(height: 12),
// 瓷套棒确认提示
Container(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
decoration: BoxDecoration(
color: AppTheme.cardBg,
borderRadius: BorderRadius.circular(6),
border: Border.all(color: AppTheme.borderSubtle, width: 1),
),
child: Row(
children: [
Container(
width: 10,
height: 10,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: AppTheme.statusStopped,
),
),
const SizedBox(width: 10),
Expanded(
child: Text(
l10n?.ceramicNotInstalled ?? '瓷套棒: 未安装 — 禁止启动',
style: const TextStyle(
color: AppTheme.textSecondary,
fontSize: 12,
),
),
),
],
),
),
const SizedBox(height: 12),
// 控制按钮
Row(
children: [
@@ -144,7 +111,7 @@ class RunningControlPanel extends ConsumerWidget {
type: ButtonType.primary,
enabled: selectedProgram != null,
onPressed: selectedProgram != null
? () => runNotifier.start(selectedProgram)
? () => _confirmAndStart(context, runNotifier, selectedProgram, l10n)
: null,
),
),
@@ -321,6 +288,49 @@ class RunningControlPanel extends ConsumerWidget {
);
}
/// 显示瓷套棒放置确认对话框,确认后启动程序
void _confirmAndStart(
BuildContext context,
RunStateNotifier runNotifier,
Program program,
AppLocalizations? l10n,
) {
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: AppTheme.cardBg,
title: Text(
l10n?.ceramicSleeveConfirm ?? '运行前请确认已安装瓷套棒',
style: const TextStyle(color: AppTheme.textHeading),
),
content: Text(
l10n?.ceramicSleeveConfirmMessage ?? '请确认已放置瓷套棒后再启动程序。',
style: const TextStyle(color: AppTheme.textPrimary),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(
l10n?.cancel ?? '取消',
style: const TextStyle(color: AppTheme.textSecondary),
),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.accentPrimary,
foregroundColor: Colors.white,
),
onPressed: () {
Navigator.of(context).pop();
runNotifier.start(program);
},
child: Text(l10n?.confirm ?? '确认'),
),
],
),
);
}
/// 显示停止确认对话框
void _showStopConfirm(
BuildContext context,

View File

@@ -6,16 +6,32 @@ import '../../../core/theme/app_theme.dart';
import '../../../shared/widgets/status_indicator.dart';
import '../../device/providers/device_info_provider.dart';
/// 状态栏标签项数据
class StatusBarTab {
final IconData icon;
final String label;
const StatusBarTab({required this.icon, required this.label});
}
/// 状态栏组件 - 明亮工业风格
/// 显示设备名称、实时时钟、系统状态、照明控制
/// 显示: 设备名称 | 导航标签 | 灯按钮 | 状态指示器 | 实时时钟
///
/// [tabs] 不为空时,会在设备名右侧渲染胶囊样式的导航标签按钮组,
/// 由父组件通过 [currentTabIndex] 和 [onTabChanged] 控制切换。
class StatusBar extends ConsumerStatefulWidget {
final bool isRunning;
final VoidCallback? onLightToggle;
final List<StatusBarTab> tabs;
final int currentTabIndex;
final ValueChanged<int>? onTabChanged;
const StatusBar({
super.key,
this.isRunning = false,
this.onLightToggle,
this.tabs = const [],
this.currentTabIndex = 0,
this.onTabChanged,
});
@override
@@ -39,6 +55,7 @@ class _StatusBarState extends ConsumerState<StatusBar> {
super.dispose();
}
/// 更新当前时间显示
void _updateTime() {
final now = DateTime.now();
_currentTime =
@@ -49,6 +66,7 @@ class _StatusBarState extends ConsumerState<StatusBar> {
String _twoDigits(int n) => n.toString().padLeft(2, '0');
/// 切换照明开关
Future<void> _onLightTap() async {
widget.onLightToggle?.call();
await ref.read(deviceInfoProvider.notifier).toggleLight();
@@ -77,7 +95,7 @@ class _StatusBarState extends ConsumerState<StatusBar> {
Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.precision_manufacturing, color: Colors.white, size: 22),
const Icon(Icons.precision_manufacturing, color: Colors.white, size: 22),
const SizedBox(width: 10),
Text(
l10n?.deviceName ?? '污水毒品前处理一体机',
@@ -89,6 +107,10 @@ class _StatusBarState extends ConsumerState<StatusBar> {
),
],
),
if (widget.tabs.isNotEmpty) ...[
const SizedBox(width: 32),
_buildNavTabs(),
],
const Spacer(),
_LightToggleButton(
isOn: deviceInfo.lightingOn,
@@ -117,6 +139,92 @@ class _StatusBarState extends ConsumerState<StatusBar> {
),
);
}
/// 构建标题栏内嵌的导航标签按钮组(胶囊样式)
Widget _buildNavTabs() {
return Row(
mainAxisSize: MainAxisSize.min,
children: List.generate(widget.tabs.length, (index) {
final tab = widget.tabs[index];
return Padding(
padding: EdgeInsets.only(right: index == widget.tabs.length - 1 ? 0 : 6),
child: _NavTabButton(
icon: tab.icon,
label: tab.label,
selected: index == widget.currentTabIndex,
onTap: () => widget.onTabChanged?.call(index),
),
);
}),
);
}
}
/// 标题栏内嵌的导航标签按钮(胶囊样式)
/// 选中时使用半透明白色背景突出,未选中时仅显示文字
class _NavTabButton extends StatelessWidget {
final IconData icon;
final String label;
final bool selected;
final VoidCallback? onTap;
const _NavTabButton({
required this.icon,
required this.label,
required this.selected,
this.onTap,
});
@override
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(18),
child: AnimatedContainer(
duration: const Duration(milliseconds: 180),
height: 36,
padding: const EdgeInsets.symmetric(horizontal: 14),
decoration: BoxDecoration(
color: selected
? Colors.white.withValues(alpha: 0.22)
: Colors.transparent,
borderRadius: BorderRadius.circular(18),
border: Border.all(
color: selected
? Colors.white.withValues(alpha: 0.35)
: Colors.transparent,
width: 1,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
icon,
size: 16,
color: selected
? Colors.white
: Colors.white.withValues(alpha: 0.78),
),
const SizedBox(width: 6),
Text(
label,
style: TextStyle(
color: selected
? Colors.white
: Colors.white.withValues(alpha: 0.85),
fontSize: 14,
fontWeight: selected ? FontWeight.w600 : FontWeight.w500,
),
),
],
),
),
),
);
}
}
class _LightToggleButton extends StatelessWidget {