feat: move sensor details to sheet, implement placement on floor plan

This commit is contained in:
2026-05-14 17:22:26 +02:00
parent 90c946d710
commit 52605f1390
12 changed files with 655 additions and 218 deletions
@@ -1,7 +1,9 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:vibration/vibration.dart';
import '../../../domain/models/floor.dart';
import '../../../domain/models/floor_plan_mode.dart';
@@ -43,6 +45,7 @@ class FloorPlanEditorState extends State<FloorPlanEditor> {
int? _selectedRoomId;
String? _selectedSensorId;
Completer<({int? roomId, double? x, double? y})>? _placementCompleter;
@override
void initState() {
@@ -82,6 +85,8 @@ class FloorPlanEditorState extends State<FloorPlanEditor> {
});
} else {
widget.onSensorTapped(id);
Vibration.hasVibrator()
.then((t) { if(t) Vibration.vibrate(duration: 20); });
}
case 'sensorMoved':
widget.onSensorMoved(
@@ -110,6 +115,12 @@ class FloorPlanEditorState extends State<FloorPlanEditor> {
_selectedRoomId = null;
_selectedSensorId = null;
});
case 'positionAtCenter':
final roomId = (data['roomId'] as num?)?.toInt();
final x = (data['x'] as num?)?.toDouble();
final y = (data['y'] as num?)?.toDouble();
_placementCompleter?.complete((roomId: roomId, x: x, y: y));
_placementCompleter = null;
}
}
@@ -208,6 +219,17 @@ class FloorPlanEditorState extends State<FloorPlanEditor> {
});
}
/// Asks JS for the room + room-relative coords at the canvas center.
/// Returns null roomId if no room is under the center dot.
Future<({int? roomId, double? x, double? y})> getPositionAtCenter() {
final c = Completer<({int? roomId, double? x, double? y})>();
_placementCompleter = c;
_run(() async {
await _controller.runJavaScript('window.companion.getPositionAtCenter()');
});
return c.future;
}
@override
Widget build(BuildContext context) {
final inEditMode = widget.mode == FloorPlanMode.edit;