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() {
|
void _cancelPlacement() {
|
||||||
ref.read(sensorPlacementProvider.notifier).state = null;
|
ref.read(sensorPlacementProvider.notifier).state = null;
|
||||||
|
ref.read(sensorPlacementOriginSensorsProvider.notifier).state = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -135,8 +136,9 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
canPop: placingSensor == null,
|
canPop: placingSensor == null,
|
||||||
onPopInvokedWithResult: (didPop, _) {
|
onPopInvokedWithResult: (didPop, _) {
|
||||||
if (!didPop && placingSensor != null) {
|
if (!didPop && placingSensor != null) {
|
||||||
|
final fromSensors = ref.read(sensorPlacementOriginSensorsProvider);
|
||||||
_cancelPlacement();
|
_cancelPlacement();
|
||||||
context.go('/sensors');
|
if (fromSensors) context.go('/sensors');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
@@ -276,8 +278,10 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
sensor: placingSensor,
|
sensor: placingSensor,
|
||||||
onPlace: () => _confirmPlacement(placingSensor),
|
onPlace: () => _confirmPlacement(placingSensor),
|
||||||
onCancel: () {
|
onCancel: () {
|
||||||
|
final fromSensors =
|
||||||
|
ref.read(sensorPlacementOriginSensorsProvider);
|
||||||
_cancelPlacement();
|
_cancelPlacement();
|
||||||
context.go('/sensors');
|
if (fromSensors) context.go('/sensors');
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -77,7 +77,10 @@ class _SensorDetailSheetState extends ConsumerState<SensorDetailSheet> {
|
|||||||
|
|
||||||
void _placeOnFloorPlan(BuildContext context, Sensor sensor) {
|
void _placeOnFloorPlan(BuildContext context, Sensor sensor) {
|
||||||
final router = GoRouter.of(context);
|
final router = GoRouter.of(context);
|
||||||
|
final fromSensors =
|
||||||
|
router.routeInformationProvider.value.uri.path == '/sensors';
|
||||||
ref.read(sensorPlacementProvider.notifier).state = sensor;
|
ref.read(sensorPlacementProvider.notifier).state = sensor;
|
||||||
|
ref.read(sensorPlacementOriginSensorsProvider.notifier).state = fromSensors;
|
||||||
Navigator.of(context, rootNavigator: true).pop();
|
Navigator.of(context, rootNavigator: true).pop();
|
||||||
router.go('/floorplan');
|
router.go('/floorplan');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,6 +166,10 @@ final tagProvider =
|
|||||||
/// center-dot placement flow. Cleared on Place, Cancel, or back navigation.
|
/// center-dot placement flow. Cleared on Place, Cancel, or back navigation.
|
||||||
final sensorPlacementProvider = StateProvider<Sensor?>((ref) => null);
|
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 =
|
final floorPlanModeProvider =
|
||||||
StateProvider<FloorPlanMode>((ref) => FloorPlanMode.view);
|
StateProvider<FloorPlanMode>((ref) => FloorPlanMode.view);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user