From 5e12fce88c640f76ba3a754312048eecfc5883e3 Mon Sep 17 00:00:00 2001 From: Songzex <2402265378@qq.com> Date: Thu, 12 Mar 2026 13:51:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B7=AF=E5=BE=84=E8=A7=84?= =?UTF-8?q?=E5=BC=80=E5=A7=8B=E5=B7=A5=E4=BD=9C=E9=87=8D=E5=A4=8D=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=A4=9A=E6=AC=A1=20=E5=AE=8C=E6=88=90=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E8=A7=84=E5=AE=8C=E6=88=90=E5=B7=A5=E4=BD=9C=E5=90=8E?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=8F=98=E6=9B=B4=E5=85=A8=E5=B1=80=E7=9A=84?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/network/net_message_dispatcher.dart | 9 +++++++++ .../devices/presentation/bloc/devices_cubit.dart | 9 +++++++++ .../devices/presentation/bloc/devices_state.dart | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/lib/core/network/net_message_dispatcher.dart b/lib/core/network/net_message_dispatcher.dart index 4754ddb5..aa5acd80 100644 --- a/lib/core/network/net_message_dispatcher.dart +++ b/lib/core/network/net_message_dispatcher.dart @@ -4,7 +4,9 @@ import 'package:flutter/cupertino.dart'; import 'package:maibu_satabot_v2/features/devices/data/models/device_add_path_point_model.dart'; import '../../features/devices/domain/repositories/route_planning_repository.dart'; +import '../../features/devices/presentation/bloc/devices_cubit.dart'; import '../../features/devices/services/path_planning_service.dart'; +import '../di/injection.dart'; import 'protocol_decoder.dart'; import 'tcp/tcp_client.dart'; // import '../../features/auth/data/models/user_model.dart'; @@ -101,6 +103,13 @@ class NetMessageDispatcher { /// _pathPlanningService.updateQueue(queue as List); _pathPlanningService.updateQueue(queue.toList()); debugPrint('📡 [Dispatcher] 准备触发下一个路径点发送,队列剩余:${queue.length}'); + ///如果还剩0个数据 就停止发送 + if (queue.length==0) { + debugPrint('⚠️ [Dispatcher] 队列已空,停止发送'); + final devicesCubit = sl(); + devicesCubit.finishWork(); + return false; + } routePlanningRepository.startRoutePlanning(queue); return true; } else { diff --git a/lib/features/devices/presentation/bloc/devices_cubit.dart b/lib/features/devices/presentation/bloc/devices_cubit.dart index 22e6f840..f85b1d57 100644 --- a/lib/features/devices/presentation/bloc/devices_cubit.dart +++ b/lib/features/devices/presentation/bloc/devices_cubit.dart @@ -398,4 +398,13 @@ class DevicesCubit extends Cubit { emit(state.copyWith(appState: appState)); (_routePlanningUseCase as dynamic).repository.setAppState(appState); } + + void finishWork() { + emit(state.copyWith(isFinshWork: true)); + } + + /// 重置完成状态 + void resetWorkStatus() { + emit(state.copyWith(isFinshWork: false)); + } } diff --git a/lib/features/devices/presentation/bloc/devices_state.dart b/lib/features/devices/presentation/bloc/devices_state.dart index 82baeb46..92930be2 100644 --- a/lib/features/devices/presentation/bloc/devices_state.dart +++ b/lib/features/devices/presentation/bloc/devices_state.dart @@ -27,6 +27,7 @@ class DevicesState extends Equatable { final List>? pathData; final List? generatedPath; // 新增字段 final AppState appState; + final bool isFinshWork; @@ -42,6 +43,7 @@ class DevicesState extends Equatable { this.pathData, this.generatedPath, this.appState = AppState.none, + this.isFinshWork = false, }); // 使用 copyWith 方便局部更新状态 @@ -57,6 +59,7 @@ class DevicesState extends Equatable { List>? pathData, List? generatedPath, AppState? appState, + bool? isFinshWork, }) { return DevicesState( devices: devices ?? this.devices, @@ -70,6 +73,7 @@ class DevicesState extends Equatable { operationType: operationType ?? this.operationType, // 更新操作类型 generatedPath: generatedPath ?? this.generatedPath, // 更新生成的路径数据 appState: appState ?? this.appState, // 更新应用状态 + isFinshWork: isFinshWork ?? this.isFinshWork, ); } @@ -83,5 +87,6 @@ class DevicesState extends Equatable { operationType, generatedPath, appState, + isFinshWork ]; }