feat: add sensor move mode to floor plan
This commit is contained in:
@@ -32,7 +32,26 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
||||
.then((rooms) => _editorKey.currentState?.loadFloorPlan(rooms));
|
||||
ref
|
||||
.read(sensorsProvider.future)
|
||||
.then((sensors) => _editorKey.currentState?.loadSensors(sensors));
|
||||
.then((sensors) {
|
||||
_editorKey.currentState?.loadSensors(sensors);
|
||||
_applyPlacementState();
|
||||
});
|
||||
}
|
||||
|
||||
void _applyPlacementState() {
|
||||
final placing = ref.read(sensorPlacementProvider);
|
||||
if (placing == null) {
|
||||
_editorKey.currentState?.highlightSensor(null);
|
||||
return;
|
||||
}
|
||||
final currentMode = ref.read(floorPlanModeProvider);
|
||||
if (currentMode != FloorPlanMode.view) {
|
||||
ref.read(floorPlanModeProvider.notifier).state = FloorPlanMode.view;
|
||||
_editorKey.currentState?.setMode(FloorPlanMode.view);
|
||||
}
|
||||
if (placing.isPlaced) {
|
||||
_editorKey.currentState?.highlightSensor(placing.id.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _confirmPlacement(Sensor sensor) async {
|
||||
@@ -81,9 +100,7 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
||||
ref.listen(particleCloudProvider, (_, next) {
|
||||
next.whenData((p) => _editorKey.currentState?.updateParticleCloud(p));
|
||||
});
|
||||
ref.listen(selectedSensorIdProvider, (_, id) {
|
||||
_editorKey.currentState?.highlightSensor(id);
|
||||
});
|
||||
ref.listen(sensorPlacementProvider, (prev, next) => _applyPlacementState());
|
||||
|
||||
final unplaced = sensorsAsync.valueOrNull
|
||||
?.where((s) => !s.isPlaced)
|
||||
@@ -103,23 +120,37 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
||||
appBar: AppBar(
|
||||
title: const Text('Floor Plan'),
|
||||
actions: [
|
||||
if (placingSensor == null)
|
||||
IconButton(
|
||||
tooltip:
|
||||
mode == FloorPlanMode.edit ? 'View mode' : 'Edit mode',
|
||||
icon: Icon(
|
||||
mode == FloorPlanMode.edit
|
||||
? Icons.visibility
|
||||
: Icons.edit,
|
||||
if (placingSensor == null) ...[
|
||||
if (mode == FloorPlanMode.view) ...[
|
||||
IconButton(
|
||||
tooltip: 'Edit mode',
|
||||
icon: const Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
ref.read(floorPlanModeProvider.notifier).state =
|
||||
FloorPlanMode.edit;
|
||||
_editorKey.currentState?.setMode(FloorPlanMode.edit);
|
||||
},
|
||||
),
|
||||
onPressed: () {
|
||||
final next = mode == FloorPlanMode.edit
|
||||
? FloorPlanMode.view
|
||||
: FloorPlanMode.edit;
|
||||
ref.read(floorPlanModeProvider.notifier).state = next;
|
||||
_editorKey.currentState?.setMode(next);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'Sensor move mode',
|
||||
icon: const Icon(Icons.sensors),
|
||||
onPressed: () {
|
||||
ref.read(floorPlanModeProvider.notifier).state =
|
||||
FloorPlanMode.sensorMove;
|
||||
_editorKey.currentState?.setMode(FloorPlanMode.sensorMove);
|
||||
},
|
||||
),
|
||||
] else
|
||||
IconButton(
|
||||
tooltip: 'Done',
|
||||
icon: const Icon(Icons.check),
|
||||
onPressed: () {
|
||||
ref.read(floorPlanModeProvider.notifier).state =
|
||||
FloorPlanMode.view;
|
||||
_editorKey.currentState?.setMode(FloorPlanMode.view);
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
@@ -131,8 +162,6 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
||||
key: _editorKey,
|
||||
mode: mode,
|
||||
onSensorTapped: (id) {
|
||||
ref.read(selectedSensorIdProvider.notifier).state =
|
||||
id;
|
||||
showSensorDetailSheet(context, int.parse(id));
|
||||
},
|
||||
onSensorMoved: (sensorId, roomId, x, y) async {
|
||||
@@ -163,8 +192,6 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
||||
},
|
||||
onRoomAdded: (x, y) => _showAddRoomDialog(x, y),
|
||||
onEditRoomTapped: _showRoomEditSheet,
|
||||
onEditSensorTapped: (id) =>
|
||||
showSensorDetailSheet(context, int.parse(id)),
|
||||
onAddSensorTapped: () => showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
|
||||
Reference in New Issue
Block a user