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 ]; }