feat(device): 启动自动连接 USB 串口 + 隐藏设置页配置项 + 标题栏连接状态
- 新增 AutoSerialConnect 服务:启动后自动连接第一个 USB 串口设备, 固定 115200/8/N/1,连接失败时每 3s 重试,断开后重新进入重试循环 - main.dart 通过 ProviderContainer 在 runApp 之前触发 autoSerialConnectProvider - 移除设置页「串口配置」菜单项及对应面板分支 - StatusBar 在「设备运行状态」前增加串口连接状态指示(已连接/连接中/未连接)
This commit is contained in:
@@ -5,6 +5,8 @@ import '../../../core/localization/app_localizations.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../../../shared/widgets/status_indicator.dart';
|
||||
import '../../device/providers/device_info_provider.dart';
|
||||
import '../../device/providers/serial_provider.dart';
|
||||
import '../../device/services/serial_port_service.dart';
|
||||
|
||||
/// 状态栏标签项数据
|
||||
class StatusBarTab {
|
||||
@@ -76,6 +78,7 @@ class _StatusBarState extends ConsumerState<StatusBar> {
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final deviceInfo = ref.watch(deviceInfoProvider);
|
||||
final serialState = ref.watch(serialPortServiceProvider).state;
|
||||
|
||||
return Container(
|
||||
height: 56,
|
||||
@@ -117,6 +120,8 @@ class _StatusBarState extends ConsumerState<StatusBar> {
|
||||
onTap: _onLightTap,
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
_SerialConnectionIndicator(state: serialState),
|
||||
const SizedBox(width: 20),
|
||||
StatusIndicator(
|
||||
text: widget.isRunning
|
||||
? (l10n?.running ?? '运行中')
|
||||
@@ -262,3 +267,49 @@ class _LightToggleButton extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 串口连接状态指示器
|
||||
///
|
||||
/// 位于「设备运行状态」之前,反映当前 USB 串口的连接情况。
|
||||
class _SerialConnectionIndicator extends StatelessWidget {
|
||||
final SerialConnectionState state;
|
||||
const _SerialConnectionIndicator({required this.state});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final connected = state == SerialConnectionState.connected;
|
||||
final connecting = state == SerialConnectionState.connecting;
|
||||
final text = connected
|
||||
? '已连接'
|
||||
: connecting
|
||||
? '连接中'
|
||||
: '未连接';
|
||||
final color = connected
|
||||
? AppTheme.statusRunning
|
||||
: connecting
|
||||
? AppTheme.statusPaused
|
||||
: AppTheme.statusStopped;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user