feat: add sensor move mode to floor plan
This commit is contained in:
@@ -20,7 +20,6 @@ class FloorPlanEditor extends StatefulWidget {
|
||||
this.onRoomsUpdated,
|
||||
this.onRoomAdded,
|
||||
this.onEditRoomTapped,
|
||||
this.onEditSensorTapped,
|
||||
this.onAddSensorTapped,
|
||||
});
|
||||
|
||||
@@ -31,7 +30,6 @@ class FloorPlanEditor extends StatefulWidget {
|
||||
final void Function(List<Room> rooms)? onRoomsUpdated;
|
||||
final void Function(double x, double y)? onRoomAdded;
|
||||
final void Function(int roomId)? onEditRoomTapped;
|
||||
final void Function(String sensorId)? onEditSensorTapped;
|
||||
final void Function()? onAddSensorTapped;
|
||||
|
||||
@override
|
||||
@@ -44,7 +42,7 @@ class FloorPlanEditorState extends State<FloorPlanEditor> {
|
||||
final _pending = <Future<void> Function()>[];
|
||||
|
||||
int? _selectedRoomId;
|
||||
String? _selectedSensorId;
|
||||
String? _repositioningSensorId;
|
||||
Completer<({int? roomId, double? x, double? y})>? _placementCompleter;
|
||||
|
||||
@override
|
||||
@@ -78,19 +76,17 @@ class FloorPlanEditorState extends State<FloorPlanEditor> {
|
||||
switch (data['type'] as String?) {
|
||||
case 'sensorTapped':
|
||||
final id = data['id'] as String;
|
||||
if (widget.mode == FloorPlanMode.edit) {
|
||||
setState(() {
|
||||
_selectedSensorId = id;
|
||||
_selectedRoomId = null;
|
||||
});
|
||||
} else {
|
||||
widget.onSensorTapped(id);
|
||||
Vibration.hasVibrator()
|
||||
.then((t) { if(t) Vibration.vibrate(duration: 20); });
|
||||
}
|
||||
widget.onSensorTapped(id);
|
||||
Vibration.hasVibrator()
|
||||
.then((t) { if (t) Vibration.vibrate(duration: 20); });
|
||||
case 'sensorMoved':
|
||||
final id = data['id'] as String;
|
||||
if (_repositioningSensorId == id) {
|
||||
setState(() => _repositioningSensorId = null);
|
||||
setRepositioningSensor(null);
|
||||
}
|
||||
widget.onSensorMoved(
|
||||
data['id'] as String,
|
||||
id,
|
||||
(data['roomId'] as num).toInt(),
|
||||
(data['x'] as num).toDouble(),
|
||||
(data['y'] as num).toDouble(),
|
||||
@@ -106,15 +102,9 @@ class FloorPlanEditorState extends State<FloorPlanEditor> {
|
||||
(data['y'] as num).toDouble(),
|
||||
);
|
||||
case 'roomTapped':
|
||||
setState(() {
|
||||
_selectedRoomId = (data['id'] as num).toInt();
|
||||
_selectedSensorId = null;
|
||||
});
|
||||
setState(() => _selectedRoomId = (data['id'] as num).toInt());
|
||||
case 'selectionCleared':
|
||||
setState(() {
|
||||
_selectedRoomId = null;
|
||||
_selectedSensorId = null;
|
||||
});
|
||||
setState(() => _selectedRoomId = null);
|
||||
case 'positionAtCenter':
|
||||
final roomId = (data['roomId'] as num?)?.toInt();
|
||||
final x = (data['x'] as num?)?.toDouble();
|
||||
@@ -204,7 +194,7 @@ class FloorPlanEditorState extends State<FloorPlanEditor> {
|
||||
Future<void> setMode(FloorPlanMode mode) {
|
||||
setState(() {
|
||||
_selectedRoomId = null;
|
||||
_selectedSensorId = null;
|
||||
_repositioningSensorId = null;
|
||||
});
|
||||
return _run(() async {
|
||||
await _controller.runJavaScript(
|
||||
@@ -213,6 +203,16 @@ class FloorPlanEditorState extends State<FloorPlanEditor> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> setRepositioningSensor(String? id) {
|
||||
setState(() => _repositioningSensorId = id);
|
||||
return _run(() async {
|
||||
final jsId = id == null ? 'null' : jsonEncode(id);
|
||||
await _controller.runJavaScript(
|
||||
'window.companion.setRepositioningSensor($jsId)',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> addRoom() {
|
||||
return _run(() async {
|
||||
await _controller.runJavaScript('window.companion.addRoom()');
|
||||
@@ -245,16 +245,6 @@ class FloorPlanEditorState extends State<FloorPlanEditor> {
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
if (inEditMode) ...[
|
||||
if (_selectedSensorId != null) ...[
|
||||
FloatingActionButton.small(
|
||||
heroTag: 'editor-info-sensor',
|
||||
tooltip: 'Sensor details',
|
||||
onPressed: () =>
|
||||
widget.onEditSensorTapped?.call(_selectedSensorId!),
|
||||
child: const Icon(Icons.info_outline),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
if (_selectedRoomId != null) ...[
|
||||
FloatingActionButton.small(
|
||||
heroTag: 'editor-edit-room',
|
||||
|
||||
Reference in New Issue
Block a user