From c58bf370e39da45444edffb1eecc42a16cdaa2c3 Mon Sep 17 00:00:00 2001 From: Songzex <2402265378@qq.com> Date: Thu, 12 Mar 2026 16:41:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=8C=E6=88=90=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E5=81=9C=E6=AD=A2=E4=B9=8B=E5=90=8E=E5=86=8D=E5=BC=80?= =?UTF-8?q?=E5=A7=8B=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repositories/route_planning_repository_impl.dart | 7 +++++++ lib/features/devices/presentation/bloc/devices_cubit.dart | 2 ++ lib/features/devices/services/path_planning_service.dart | 1 + .../home/presentation/widgets/map/testmap_pages.dart | 8 +++++++- 4 files changed, 17 insertions(+), 1 deletion(-) 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));