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

@@ -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 {