diff --git a/lib/features/devices/data/repositories/route_planning_repository_impl.dart b/lib/features/devices/data/repositories/route_planning_repository_impl.dart index 43009ed9..95316d3a 100644 --- a/lib/features/devices/data/repositories/route_planning_repository_impl.dart +++ b/lib/features/devices/data/repositories/route_planning_repository_impl.dart @@ -181,6 +181,13 @@ class PathPlanner { _isStopped = true; _isPaused = false; // 清除暂停状态 + // 🔥 核心修复:清空队列 + print("🗑️ 清空待发送队列,剩余 ${locationQueue.length} 个点"); + locationQueue.clear(); + + + + var entity = new RoutePlanSendEntity( commandType: 0x01, pointCounts: 0, diff --git a/lib/features/devices/presentation/bloc/devices_cubit.dart b/lib/features/devices/presentation/bloc/devices_cubit.dart index 189f6dd4..2abf775a 100644 --- a/lib/features/devices/presentation/bloc/devices_cubit.dart +++ b/lib/features/devices/presentation/bloc/devices_cubit.dart @@ -391,6 +391,8 @@ class DevicesCubit extends Cubit { Future stopRoutePlanning() async { emit(state.copyWith(isLoading: true)); final result = await _routePlanningUseCase.stopRoutePlanning(); + // 🔥 重置 PathPlanningService 中的全局的队列 + _pathPlanningService.clear(); result.fold((failure) => emit(state.copyWith(isLoading: false, errorMessage: failure.message ?? '停止失败')), (_) => emit(state.copyWith(isLoading: false))); } diff --git a/lib/features/devices/services/path_planning_service.dart b/lib/features/devices/services/path_planning_service.dart index 902d21c6..c5bb3f49 100644 --- a/lib/features/devices/services/path_planning_service.dart +++ b/lib/features/devices/services/path_planning_service.dart @@ -73,4 +73,5 @@ class PathPlanningService { Queue getQueue() { return Queue.of(locationQueue); } + } diff --git a/lib/features/home/presentation/widgets/map/testmap_pages.dart b/lib/features/home/presentation/widgets/map/testmap_pages.dart index c993a72d..4e22edfa 100644 --- a/lib/features/home/presentation/widgets/map/testmap_pages.dart +++ b/lib/features/home/presentation/widgets/map/testmap_pages.dart @@ -1485,6 +1485,12 @@ class _MapPageEnterpriseState extends State { _workStatus = WorkStatus.working; }); + // 🔥 核心修复:先更新 AppState 为 routePlanning + context.read().updateAppState(AppState.routePlanning); + // 🔥 延迟一下,确保状态已更新 + await Future.delayed(const Duration(milliseconds: 100)); + + //// 步骤1:将 List 转换为 List //final List pathModels = gcjPathPoints.map((latLng) { // return work_area_model.DeviceAddPathPointModel( @@ -1502,7 +1508,7 @@ class _MapPageEnterpriseState extends State { // 步骤 3:调用 Cubit 方法(类型匹配) await context.read().startRoutePlanning(pathQueue); - context.read().updateAppState(AppState.routePlanning); + ///context.read().updateAppState(AppState.routePlanning); // 可选:显示作业提示 ToastUtils.showSuccess(context, '作业已开始'); //ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('作业已开始'), backgroundColor: Colors.green));