From c54631bcb6dd9449dcbb1d2e8e6198a0cebe47dc Mon Sep 17 00:00:00 2001 From: dvdrw Date: Mon, 18 May 2026 19:27:08 +0200 Subject: [PATCH] fix: return to sensors list after cancelling reposition only if you've arrived from there --- lib/features/floorplan/floor_plan_screen.dart | 8 ++++++-- lib/features/sensors/sensor_detail_sheet.dart | 3 +++ lib/providers.dart | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/features/floorplan/floor_plan_screen.dart b/lib/features/floorplan/floor_plan_screen.dart index c9403fd..5709588 100644 --- a/lib/features/floorplan/floor_plan_screen.dart +++ b/lib/features/floorplan/floor_plan_screen.dart @@ -80,6 +80,7 @@ class _FloorPlanScreenState extends ConsumerState { void _cancelPlacement() { ref.read(sensorPlacementProvider.notifier).state = null; + ref.read(sensorPlacementOriginSensorsProvider.notifier).state = false; } @override @@ -135,8 +136,9 @@ class _FloorPlanScreenState extends ConsumerState { canPop: placingSensor == null, onPopInvokedWithResult: (didPop, _) { if (!didPop && placingSensor != null) { + final fromSensors = ref.read(sensorPlacementOriginSensorsProvider); _cancelPlacement(); - context.go('/sensors'); + if (fromSensors) context.go('/sensors'); } }, child: Scaffold( @@ -276,8 +278,10 @@ class _FloorPlanScreenState extends ConsumerState { sensor: placingSensor, onPlace: () => _confirmPlacement(placingSensor), onCancel: () { + final fromSensors = + ref.read(sensorPlacementOriginSensorsProvider); _cancelPlacement(); - context.go('/sensors'); + if (fromSensors) context.go('/sensors'); }, ), ), diff --git a/lib/features/sensors/sensor_detail_sheet.dart b/lib/features/sensors/sensor_detail_sheet.dart index 713a5b2..d4c1a41 100644 --- a/lib/features/sensors/sensor_detail_sheet.dart +++ b/lib/features/sensors/sensor_detail_sheet.dart @@ -77,7 +77,10 @@ class _SensorDetailSheetState extends ConsumerState { void _placeOnFloorPlan(BuildContext context, Sensor sensor) { final router = GoRouter.of(context); + final fromSensors = + router.routeInformationProvider.value.uri.path == '/sensors'; ref.read(sensorPlacementProvider.notifier).state = sensor; + ref.read(sensorPlacementOriginSensorsProvider.notifier).state = fromSensors; Navigator.of(context, rootNavigator: true).pop(); router.go('/floorplan'); } diff --git a/lib/providers.dart b/lib/providers.dart index f3c516d..13da862 100644 --- a/lib/providers.dart +++ b/lib/providers.dart @@ -166,6 +166,10 @@ final tagProvider = /// center-dot placement flow. Cleared on Place, Cancel, or back navigation. final sensorPlacementProvider = StateProvider((ref) => null); +/// True when placement mode was initiated from the sensors list tab. +/// Used by FloorPlanScreen to decide whether to navigate back on cancel. +final sensorPlacementOriginSensorsProvider = StateProvider((ref) => false); + final floorPlanModeProvider = StateProvider((ref) => FloorPlanMode.view);