fix: revert room name/width/height on edit discard
This commit is contained in:
@@ -48,4 +48,18 @@ class Room {
|
|||||||
'width': width,
|
'width': width,
|
||||||
'height': height,
|
'height': height,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if(other is! Room) {
|
||||||
|
return super == other;
|
||||||
|
}
|
||||||
|
|
||||||
|
return other.height == height
|
||||||
|
&& other.width == width
|
||||||
|
&& other.name == name
|
||||||
|
&& other.id == id
|
||||||
|
&& other.x == x
|
||||||
|
&& other.y == y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
|
import '../../domain/models/floor.dart';
|
||||||
import '../../domain/models/floor_plan_mode.dart';
|
import '../../domain/models/floor_plan_mode.dart';
|
||||||
import '../../domain/models/sensor.dart';
|
import '../../domain/models/sensor.dart';
|
||||||
import '../../domain/models/tag.dart';
|
import '../../domain/models/tag.dart';
|
||||||
@@ -21,6 +22,9 @@ class FloorPlanScreen extends ConsumerStatefulWidget {
|
|||||||
class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
||||||
final _editorKey = GlobalKey<FloorPlanEditorState>();
|
final _editorKey = GlobalKey<FloorPlanEditorState>();
|
||||||
|
|
||||||
|
List<Room>? _editModeOriginalRooms;
|
||||||
|
List<Room>? _pendingRoomUpdates;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -31,12 +35,10 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
ref
|
ref
|
||||||
.read(roomsProvider.future)
|
.read(roomsProvider.future)
|
||||||
.then((rooms) => _editorKey.currentState?.loadFloorPlan(rooms));
|
.then((rooms) => _editorKey.currentState?.loadFloorPlan(rooms));
|
||||||
ref
|
ref.read(sensorsProvider.future).then((sensors) {
|
||||||
.read(sensorsProvider.future)
|
_editorKey.currentState?.loadSensors(sensors);
|
||||||
.then((sensors) {
|
_applyPlacementState();
|
||||||
_editorKey.currentState?.loadSensors(sensors);
|
});
|
||||||
_applyPlacementState();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _applyPlacementState() {
|
void _applyPlacementState() {
|
||||||
@@ -56,18 +58,17 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _confirmPlacement(Sensor sensor) async {
|
Future<void> _confirmPlacement(Sensor sensor) async {
|
||||||
final result =
|
final result = await _editorKey.currentState?.getPositionAtCenter();
|
||||||
await _editorKey.currentState?.getPositionAtCenter();
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
if (result == null || result.roomId == null) {
|
if (result == null || result.roomId == null) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(content: Text('Move the map so the dot is over a room')),
|
||||||
content: Text('Move the map so the dot is over a room'),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await ref.read(sensorRepositoryProvider).placeSensor(
|
await ref
|
||||||
|
.read(sensorRepositoryProvider)
|
||||||
|
.placeSensor(
|
||||||
sensor.id,
|
sensor.id,
|
||||||
roomId: result.roomId!,
|
roomId: result.roomId!,
|
||||||
x: result.x!,
|
x: result.x!,
|
||||||
@@ -105,8 +106,10 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
case 'sensor_enrollment_timeout':
|
case 'sensor_enrollment_timeout':
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
content: Text('Sensor did not come online in time. '
|
content: Text(
|
||||||
'Check WiFi credentials and try again.'),
|
'Sensor did not come online in time. '
|
||||||
|
'Check WiFi credentials and try again.',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -118,7 +121,9 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
if (trackedTag != null) {
|
if (trackedTag != null) {
|
||||||
ref.listen(particleSnapshotProvider(trackedTag.tagId), (_, next) {
|
ref.listen(particleSnapshotProvider(trackedTag.tagId), (_, next) {
|
||||||
next.whenData(
|
next.whenData(
|
||||||
(snap) => _editorKey.currentState?.updateParticleCloud(snap.particles));
|
(snap) =>
|
||||||
|
_editorKey.currentState?.updateParticleCloud(snap.particles),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ref.listen(trackedTagProvider, (prev, next) {
|
ref.listen(trackedTagProvider, (prev, next) {
|
||||||
@@ -126,10 +131,8 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
});
|
});
|
||||||
ref.listen(sensorPlacementProvider, (prev, next) => _applyPlacementState());
|
ref.listen(sensorPlacementProvider, (prev, next) => _applyPlacementState());
|
||||||
|
|
||||||
final unplaced = sensorsAsync.valueOrNull
|
final unplaced =
|
||||||
?.where((s) => !s.isPlaced)
|
sensorsAsync.valueOrNull?.where((s) => !s.isPlaced).toList() ?? [];
|
||||||
.toList() ??
|
|
||||||
[];
|
|
||||||
|
|
||||||
return PopScope(
|
return PopScope(
|
||||||
// While placing, intercept back: cancel placement and go to sensors list.
|
// While placing, intercept back: cancel placement and go to sensors list.
|
||||||
@@ -151,6 +154,11 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
tooltip: 'Edit mode',
|
tooltip: 'Edit mode',
|
||||||
icon: const Icon(Icons.edit),
|
icon: const Icon(Icons.edit),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
_editModeOriginalRooms = ref
|
||||||
|
.read(roomsProvider)
|
||||||
|
.valueOrNull
|
||||||
|
?.toList();
|
||||||
|
_pendingRoomUpdates = null;
|
||||||
ref.read(floorPlanModeProvider.notifier).state =
|
ref.read(floorPlanModeProvider.notifier).state =
|
||||||
FloorPlanMode.edit;
|
FloorPlanMode.edit;
|
||||||
_editorKey.currentState?.setMode(FloorPlanMode.edit);
|
_editorKey.currentState?.setMode(FloorPlanMode.edit);
|
||||||
@@ -165,16 +173,29 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
_editorKey.currentState?.setMode(FloorPlanMode.sensorMove);
|
_editorKey.currentState?.setMode(FloorPlanMode.sensorMove);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
] else
|
] else ...[
|
||||||
IconButton(
|
if (mode == FloorPlanMode.edit) ...[
|
||||||
tooltip: 'Done',
|
IconButton(
|
||||||
icon: const Icon(Icons.check),
|
tooltip: 'Discard changes',
|
||||||
onPressed: () {
|
icon: const Icon(Icons.close),
|
||||||
ref.read(floorPlanModeProvider.notifier).state =
|
onPressed: _discardRoomEdits,
|
||||||
FloorPlanMode.view;
|
),
|
||||||
_editorKey.currentState?.setMode(FloorPlanMode.view);
|
IconButton(
|
||||||
},
|
tooltip: 'Save changes',
|
||||||
),
|
icon: const Icon(Icons.check),
|
||||||
|
onPressed: _saveRoomEdits,
|
||||||
|
),
|
||||||
|
] else
|
||||||
|
IconButton(
|
||||||
|
tooltip: 'Done',
|
||||||
|
icon: const Icon(Icons.check),
|
||||||
|
onPressed: () {
|
||||||
|
ref.read(floorPlanModeProvider.notifier).state =
|
||||||
|
FloorPlanMode.view;
|
||||||
|
_editorKey.currentState?.setMode(FloorPlanMode.view);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -193,61 +214,45 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
final id = int.parse(sensorId);
|
final id = int.parse(sensorId);
|
||||||
await ref
|
await ref
|
||||||
.read(sensorRepositoryProvider)
|
.read(sensorRepositoryProvider)
|
||||||
.placeSensor(
|
.placeSensor(id, roomId: roomId, x: x, y: y);
|
||||||
id,
|
|
||||||
roomId: roomId,
|
|
||||||
x: x,
|
|
||||||
y: y,
|
|
||||||
);
|
|
||||||
ref.invalidate(sensorsProvider);
|
ref.invalidate(sensorsProvider);
|
||||||
ref.invalidate(sensorProvider(id));
|
ref.invalidate(sensorProvider(id));
|
||||||
},
|
},
|
||||||
onRoomsUpdated: (roomUpdates) async {
|
onRoomsUpdated: (roomUpdates) {
|
||||||
final floor = ref.read(floorProvider).valueOrNull;
|
setState(() => _pendingRoomUpdates = roomUpdates);
|
||||||
if (floor == null) return;
|
|
||||||
final repo = ref.read(floorRepositoryProvider);
|
|
||||||
for (final r in roomUpdates) {
|
|
||||||
await repo.updateRoom(floor.id, r.id,
|
|
||||||
x: r.x, y: r.y);
|
|
||||||
}
|
|
||||||
// Do NOT invalidate roomsProvider here: the JS canvas is
|
|
||||||
// already showing the correct positions, and re-fetching
|
|
||||||
// would replace rooms[] with a fresh array, orphaning the
|
|
||||||
// drag-closure references and causing snap-back.
|
|
||||||
},
|
},
|
||||||
onRoomAdded: (x, y) => _showAddRoomDialog(x, y),
|
onRoomAdded: (x, y) => _showAddRoomDialog(x, y),
|
||||||
onEditRoomTapped: _showRoomEditSheet,
|
onEditRoomTapped: _showRoomEditSheet,
|
||||||
onAddSensorTapped: () => showModalBottomSheet<void>(
|
onAddSensorTapped: () =>
|
||||||
context: context,
|
showModalBottomSheet<void>(
|
||||||
isScrollControlled: true,
|
context: context,
|
||||||
useRootNavigator: true,
|
isScrollControlled: true,
|
||||||
builder: (_) => const BleProvisionSheet(),
|
useRootNavigator: true,
|
||||||
).then((_) {
|
builder: (_) => const BleProvisionSheet(),
|
||||||
ref.invalidate(sensorsProvider);
|
).then((_) {
|
||||||
}),
|
ref.invalidate(sensorsProvider);
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
if (roomsAsync.valueOrNull?.isEmpty ?? false)
|
if (roomsAsync.valueOrNull?.isEmpty ?? false)
|
||||||
Center(
|
Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.map_outlined,
|
Icon(
|
||||||
size: 64, color: Colors.grey.shade400),
|
Icons.map_outlined,
|
||||||
|
size: 64,
|
||||||
|
color: Colors.grey.shade400,
|
||||||
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Text(
|
Text(
|
||||||
'No rooms yet',
|
'No rooms yet',
|
||||||
style: Theme.of(context)
|
style: Theme.of(context).textTheme.titleMedium
|
||||||
.textTheme
|
?.copyWith(color: Colors.grey.shade600),
|
||||||
.titleMedium
|
|
||||||
?.copyWith(
|
|
||||||
color: Colors.grey.shade600),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Text(
|
Text(
|
||||||
'Switch to edit mode and tap + to add a room',
|
'Switch to edit mode and tap + to add a room',
|
||||||
style: Theme.of(context)
|
style: Theme.of(context).textTheme.bodySmall
|
||||||
.textTheme
|
|
||||||
.bodySmall
|
|
||||||
?.copyWith(color: Colors.grey.shade500),
|
?.copyWith(color: Colors.grey.shade500),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
@@ -278,8 +283,9 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
sensor: placingSensor,
|
sensor: placingSensor,
|
||||||
onPlace: () => _confirmPlacement(placingSensor),
|
onPlace: () => _confirmPlacement(placingSensor),
|
||||||
onCancel: () {
|
onCancel: () {
|
||||||
final fromSensors =
|
final fromSensors = ref.read(
|
||||||
ref.read(sensorPlacementOriginSensorsProvider);
|
sensorPlacementOriginSensorsProvider,
|
||||||
|
);
|
||||||
_cancelPlacement();
|
_cancelPlacement();
|
||||||
if (fromSensors) context.go('/sensors');
|
if (fromSensors) context.go('/sensors');
|
||||||
},
|
},
|
||||||
@@ -299,18 +305,94 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _saveRoomEdits() async {
|
||||||
|
final updates = _pendingRoomUpdates;
|
||||||
|
final originals = _editModeOriginalRooms ?? [];
|
||||||
|
_editModeOriginalRooms = null;
|
||||||
|
_pendingRoomUpdates = null;
|
||||||
|
// Optimistic: switch to view immediately for responsive UX.
|
||||||
|
ref.read(floorPlanModeProvider.notifier).state = FloorPlanMode.view;
|
||||||
|
_editorKey.currentState?.setMode(FloorPlanMode.view);
|
||||||
|
if (updates != null) {
|
||||||
|
final floor = ref.read(floorProvider).valueOrNull;
|
||||||
|
if (floor != null) {
|
||||||
|
final repo = ref.read(floorRepositoryProvider);
|
||||||
|
try {
|
||||||
|
for (final r in updates) {
|
||||||
|
final orig = originals.where((o) => o.id == r.id).firstOrNull;
|
||||||
|
if (orig == null || orig != r) {
|
||||||
|
await repo.updateRoom(
|
||||||
|
floor.id,
|
||||||
|
r.id,
|
||||||
|
x: r.x,
|
||||||
|
y: r.y,
|
||||||
|
name: r.name,
|
||||||
|
width: r.width,
|
||||||
|
height: r.height,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('Failed to save floor plan changes'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
_editorKey.currentState?.loadFloorPlan(originals);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
ref.invalidate(roomsProvider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _discardRoomEdits() {
|
||||||
|
final original = _editModeOriginalRooms;
|
||||||
|
_editModeOriginalRooms = null;
|
||||||
|
_pendingRoomUpdates = null;
|
||||||
|
if (original != null) {
|
||||||
|
_editorKey.currentState?.loadFloorPlan(original);
|
||||||
|
}
|
||||||
|
ref.read(floorPlanModeProvider.notifier).state = FloorPlanMode.view;
|
||||||
|
_editorKey.currentState?.setMode(FloorPlanMode.view);
|
||||||
|
}
|
||||||
|
|
||||||
void _showRoomEditSheet(int roomId) {
|
void _showRoomEditSheet(int roomId) {
|
||||||
final rooms = ref.read(roomsProvider).valueOrNull ?? [];
|
final room =
|
||||||
final room = rooms.where((r) => r.id == roomId).firstOrNull;
|
_pendingRoomUpdates?.where((r) => r.id == roomId).firstOrNull ??
|
||||||
|
_editModeOriginalRooms?.where((r) => r.id == roomId).firstOrNull;
|
||||||
if (room == null) return;
|
if (room == null) return;
|
||||||
final floor = ref.read(floorProvider).valueOrNull;
|
|
||||||
if (floor == null) return;
|
|
||||||
showModalBottomSheet<void>(
|
showModalBottomSheet<void>(
|
||||||
context: context,
|
context: context,
|
||||||
useRootNavigator: true,
|
useRootNavigator: true,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
builder: (_) => RoomEditSheet(room: room, floorId: floor.id),
|
builder: (_) => RoomEditSheet(
|
||||||
).then((_) => ref.invalidate(roomsProvider));
|
room: room,
|
||||||
|
onSaved: (name, width, height) {
|
||||||
|
final current =
|
||||||
|
_pendingRoomUpdates ??
|
||||||
|
(ref.read(roomsProvider).valueOrNull ?? []);
|
||||||
|
setState(() {
|
||||||
|
_pendingRoomUpdates = current.map((r) {
|
||||||
|
if (r.id != roomId) return r;
|
||||||
|
return Room(
|
||||||
|
id: r.id,
|
||||||
|
name: name,
|
||||||
|
floorId: r.floorId,
|
||||||
|
x: r.x,
|
||||||
|
y: r.y,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
});
|
||||||
|
_editorKey.currentState?.loadFloorPlan(_pendingRoomUpdates ?? []);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _showAddRoomDialog(double x, double y) async {
|
Future<void> _showAddRoomDialog(double x, double y) async {
|
||||||
@@ -338,9 +420,12 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
child: TextField(
|
child: TextField(
|
||||||
controller: widthCtrl,
|
controller: widthCtrl,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Width', suffixText: 'm'),
|
labelText: 'Width',
|
||||||
|
suffixText: 'm',
|
||||||
|
),
|
||||||
keyboardType: const TextInputType.numberWithOptions(
|
keyboardType: const TextInputType.numberWithOptions(
|
||||||
decimal: true),
|
decimal: true,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
@@ -348,9 +433,12 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
child: TextField(
|
child: TextField(
|
||||||
controller: heightCtrl,
|
controller: heightCtrl,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Height', suffixText: 'm'),
|
labelText: 'Height',
|
||||||
|
suffixText: 'm',
|
||||||
|
),
|
||||||
keyboardType: const TextInputType.numberWithOptions(
|
keyboardType: const TextInputType.numberWithOptions(
|
||||||
decimal: true),
|
decimal: true,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -385,7 +473,9 @@ class _FloorPlanScreenState extends ConsumerState<FloorPlanScreen> {
|
|||||||
ref.invalidate(floorProvider);
|
ref.invalidate(floorProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
await ref.read(floorRepositoryProvider).createRoom(
|
await ref
|
||||||
|
.read(floorRepositoryProvider)
|
||||||
|
.createRoom(
|
||||||
floor.id,
|
floor.id,
|
||||||
name: name,
|
name: name,
|
||||||
width: width,
|
width: width,
|
||||||
@@ -438,8 +528,10 @@ class _TrackingCard extends StatelessWidget {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(tag.name, style: theme.textTheme.labelLarge),
|
Text(tag.name, style: theme.textTheme.labelLarge),
|
||||||
Text('Tracking particle cloud',
|
Text(
|
||||||
style: theme.textTheme.bodySmall),
|
'Tracking particle cloud',
|
||||||
|
style: theme.textTheme.bodySmall,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -478,10 +570,11 @@ class _PlacementCard extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(sensor.displayName,
|
Text(sensor.displayName, style: theme.textTheme.labelLarge),
|
||||||
style: theme.textTheme.labelLarge),
|
Text(
|
||||||
Text('Pan to position, then tap Place',
|
'Pan to position, then tap Place',
|
||||||
style: theme.textTheme.bodySmall),
|
style: theme.textTheme.bodySmall,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -509,8 +602,10 @@ class _UnplacedPanel extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text('Unplaced sensors',
|
Text(
|
||||||
style: Theme.of(context).textTheme.labelSmall),
|
'Unplaced sensors',
|
||||||
|
style: Theme.of(context).textTheme.labelSmall,
|
||||||
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
@@ -520,11 +615,12 @@ class _UnplacedPanel extends StatelessWidget {
|
|||||||
(s) => Padding(
|
(s) => Padding(
|
||||||
padding: const EdgeInsets.only(right: 8),
|
padding: const EdgeInsets.only(right: 8),
|
||||||
child: ActionChip(
|
child: ActionChip(
|
||||||
avatar: const Icon(Icons.sensors_off_outlined,
|
avatar: const Icon(
|
||||||
size: 16),
|
Icons.sensors_off_outlined,
|
||||||
|
size: 16,
|
||||||
|
),
|
||||||
label: Text(s.displayName),
|
label: Text(s.displayName),
|
||||||
onPressed: () =>
|
onPressed: () => showSensorDetailSheet(context, s.id),
|
||||||
showSensorDetailSheet(context, s.id),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,24 +1,25 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
|
|
||||||
import '../../../domain/models/floor.dart';
|
import '../../../domain/models/floor.dart';
|
||||||
import '../../../providers.dart';
|
|
||||||
|
|
||||||
class RoomEditSheet extends ConsumerStatefulWidget {
|
class RoomEditSheet extends StatefulWidget {
|
||||||
const RoomEditSheet({super.key, required this.room, required this.floorId});
|
const RoomEditSheet({
|
||||||
|
super.key,
|
||||||
|
required this.room,
|
||||||
|
required this.onSaved,
|
||||||
|
});
|
||||||
|
|
||||||
final Room room;
|
final Room room;
|
||||||
final int floorId;
|
final void Function(String name, double width, double height) onSaved;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<RoomEditSheet> createState() => _RoomEditSheetState();
|
State<RoomEditSheet> createState() => _RoomEditSheetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RoomEditSheetState extends ConsumerState<RoomEditSheet> {
|
class _RoomEditSheetState extends State<RoomEditSheet> {
|
||||||
late final TextEditingController _nameCtrl;
|
late final TextEditingController _nameCtrl;
|
||||||
late final TextEditingController _widthCtrl;
|
late final TextEditingController _widthCtrl;
|
||||||
late final TextEditingController _heightCtrl;
|
late final TextEditingController _heightCtrl;
|
||||||
bool _saving = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -36,25 +37,14 @@ class _RoomEditSheetState extends ConsumerState<RoomEditSheet> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _save() async {
|
void _save() {
|
||||||
final name = _nameCtrl.text.trim();
|
final name = _nameCtrl.text.trim();
|
||||||
final width = double.tryParse(_widthCtrl.text);
|
final width = double.tryParse(_widthCtrl.text);
|
||||||
final height = double.tryParse(_heightCtrl.text);
|
final height = double.tryParse(_heightCtrl.text);
|
||||||
if (name.isEmpty || width == null || height == null) return;
|
if (name.isEmpty || width == null || height == null) return;
|
||||||
|
|
||||||
setState(() => _saving = true);
|
widget.onSaved(name, width, height);
|
||||||
try {
|
Navigator.of(context).pop();
|
||||||
await ref.read(floorRepositoryProvider).updateRoom(
|
|
||||||
widget.floorId,
|
|
||||||
widget.room.id,
|
|
||||||
name: name,
|
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
);
|
|
||||||
if (mounted) Navigator.of(context).pop();
|
|
||||||
} finally {
|
|
||||||
if (mounted) setState(() => _saving = false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -103,14 +93,8 @@ class _RoomEditSheetState extends ConsumerState<RoomEditSheet> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
FilledButton(
|
FilledButton(
|
||||||
onPressed: _saving ? null : _save,
|
onPressed: _save,
|
||||||
child: _saving
|
child: const Text('Save'),
|
||||||
? const SizedBox(
|
|
||||||
height: 20,
|
|
||||||
width: 20,
|
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
|
||||||
)
|
|
||||||
: const Text('Save'),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user