fix: return to sensors list after cancelling reposition only if you've arrived from there
This commit is contained in:
@@ -80,6 +80,7 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
||||
|
||||
void _cancelPlacement() {
|
||||
ref.read(sensorPlacementProvider.notifier).state = null;
|
||||
ref.read(sensorPlacementOriginSensorsProvider.notifier).state = false;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -135,8 +136,9 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
||||
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<FloorPlanScreen> {
|
||||
sensor: placingSensor,
|
||||
onPlace: () => _confirmPlacement(placingSensor),
|
||||
onCancel: () {
|
||||
final fromSensors =
|
||||
ref.read(sensorPlacementOriginSensorsProvider);
|
||||
_cancelPlacement();
|
||||
context.go('/sensors');
|
||||
if (fromSensors) context.go('/sensors');
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -77,7 +77,10 @@ class _SensorDetailSheetState extends ConsumerState<SensorDetailSheet> {
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
@@ -166,6 +166,10 @@ final tagProvider =
|
||||
/// center-dot placement flow. Cleared on Place, Cancel, or back navigation.
|
||||
final sensorPlacementProvider = StateProvider<Sensor?>((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<bool>((ref) => false);
|
||||
|
||||
final floorPlanModeProvider =
|
||||
StateProvider<FloorPlanMode>((ref) => FloorPlanMode.view);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user