按 docs/下位机交互数据模型.md 重构串口协议层: 协议层 - 新增 DeviceMessage 模型,对应 message_id/type/ack/need_ack/data - 新增 JsonProtocolService,4 字节大端长度前缀 + UTF-8 JSON 帧 - 删除原二进制协议(serial_protocol.dart) 服务层 - 新增 DeviceMessageService,集中收发并按 type 分发 - 重写 SerialRunner 为 JsonSerialRunner,使用 create_task/control 消息 数据模型 - DeviceState 增加 doorStatus/lightStatus/taskStatus/lastInfoAt - 新增 DeviceInfoNotifier 订阅 device_info 上行 - 灯光按钮接通 light_control 消息 测试 - 新增 device_protocol_test.dart(14 用例) - 修复 models_test.dart 残留的 Step mixSpeed/blowSpeed 错误
168 lines
5.1 KiB
Dart
168 lines
5.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../../core/database/database_service.dart';
|
|
import '../../../core/theme/app_theme.dart';
|
|
import '../../device/providers/run_state_provider.dart';
|
|
import '../../programs/pages/programs_page.dart';
|
|
import '../../settings/pages/settings_page.dart';
|
|
import '../widgets/status_bar.dart';
|
|
import '../widgets/program_list.dart';
|
|
import '../widgets/running_control_panel.dart';
|
|
import '../widgets/run_status_monitor.dart';
|
|
|
|
/// 首页 - 设备控制面板 (暗色工业风格)
|
|
/// 布局:状态栏 + 导航标签栏 + 内容区(设备控制/程序管理/系统设置)
|
|
class HomePage extends ConsumerStatefulWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
ConsumerState<HomePage> createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends ConsumerState<HomePage>
|
|
with SingleTickerProviderStateMixin {
|
|
int _currentIndex = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
DatabaseService.instance.initTestData();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final runState = ref.watch(runStateProvider);
|
|
|
|
// 监听运行完成状态,自动跳转
|
|
ref.listen<RunState>(runStateProvider, (prev, next) {
|
|
if (prev?.status != RunStatus.completed && next.status == RunStatus.completed) {
|
|
// 仅首页才自动跳转
|
|
if (_currentIndex == 0) {
|
|
context.push('/complete');
|
|
}
|
|
}
|
|
});
|
|
|
|
return Scaffold(
|
|
body: Container(
|
|
color: AppTheme.bgDeep,
|
|
child: Column(
|
|
children: [
|
|
// 状态栏
|
|
StatusBar(
|
|
isRunning: runState.status == RunStatus.running,
|
|
),
|
|
|
|
// 导航标签栏
|
|
_buildTabBar(),
|
|
|
|
// 内容区
|
|
Expanded(
|
|
child: IndexedStack(
|
|
index: _currentIndex,
|
|
children: [
|
|
_buildDeviceControlPage(runState),
|
|
const ProgramsPage(),
|
|
const SettingsPage(),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 导航标签栏
|
|
Widget _buildTabBar() {
|
|
const tabs = [
|
|
(icon: Icons.dashboard, label: '设备控制'),
|
|
(icon: Icons.list_alt, label: '程序管理'),
|
|
(icon: Icons.settings, label: '系统设置'),
|
|
];
|
|
|
|
return Container(
|
|
height: 48,
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: Row(
|
|
children: List.generate(tabs.length, (index) {
|
|
final tab = tabs[index];
|
|
final isSelected = _currentIndex == index;
|
|
return GestureDetector(
|
|
onTap: () => setState(() => _currentIndex = index),
|
|
child: AnimatedContainer(
|
|
duration: const Duration(milliseconds: 200),
|
|
margin: const EdgeInsets.only(right: 4),
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
decoration: BoxDecoration(
|
|
color: isSelected ? AppTheme.accentPrimary : AppTheme.cardBg,
|
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(8)),
|
|
border: Border.all(
|
|
color: isSelected
|
|
? AppTheme.accentPrimary
|
|
: AppTheme.borderSubtle,
|
|
width: 1,
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(
|
|
tab.icon,
|
|
size: 18,
|
|
color: isSelected ? Colors.white : AppTheme.textSecondary,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
tab.label,
|
|
style: TextStyle(
|
|
color: isSelected ? Colors.white : AppTheme.textSecondary,
|
|
fontSize: 14,
|
|
fontWeight: isSelected
|
|
? FontWeight.w600
|
|
: FontWeight.normal,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 设备控制页面内容
|
|
Widget _buildDeviceControlPage(RunState runState) {
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
|
|
child: Row(
|
|
children: [
|
|
// 左侧:程序列表(运行时锁定)
|
|
Opacity(
|
|
opacity: runState.status == RunStatus.idle ? 1.0 : 0.6,
|
|
child: IgnorePointer(
|
|
ignoring: runState.status != RunStatus.idle,
|
|
child: const ProgramList(),
|
|
),
|
|
),
|
|
const SizedBox(width: 20),
|
|
// 右侧:运行控制区域
|
|
Expanded(
|
|
child: Column(
|
|
children: [
|
|
const Expanded(child: RunningControlPanel()),
|
|
if (runState.status != RunStatus.idle) ...[
|
|
const SizedBox(height: 16),
|
|
const Expanded(child: RunStatusMonitor()),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|