fix: revert room name/width/height on edit discard
This commit is contained in:
@@ -1,24 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../domain/models/floor.dart';
|
||||
import '../../../providers.dart';
|
||||
|
||||
class RoomEditSheet extends ConsumerStatefulWidget {
|
||||
const RoomEditSheet({super.key, required this.room, required this.floorId});
|
||||
class RoomEditSheet extends StatefulWidget {
|
||||
const RoomEditSheet({
|
||||
super.key,
|
||||
required this.room,
|
||||
required this.onSaved,
|
||||
});
|
||||
|
||||
final Room room;
|
||||
final int floorId;
|
||||
final void Function(String name, double width, double height) onSaved;
|
||||
|
||||
@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 _widthCtrl;
|
||||
late final TextEditingController _heightCtrl;
|
||||
bool _saving = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -36,25 +37,14 @@ class _RoomEditSheetState extends ConsumerState<RoomEditSheet> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
void _save() {
|
||||
final name = _nameCtrl.text.trim();
|
||||
final width = double.tryParse(_widthCtrl.text);
|
||||
final height = double.tryParse(_heightCtrl.text);
|
||||
if (name.isEmpty || width == null || height == null) return;
|
||||
|
||||
setState(() => _saving = true);
|
||||
try {
|
||||
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);
|
||||
}
|
||||
widget.onSaved(name, width, height);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -103,14 +93,8 @@ class _RoomEditSheetState extends ConsumerState<RoomEditSheet> {
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton(
|
||||
onPressed: _saving ? null : _save,
|
||||
child: _saving
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Text('Save'),
|
||||
onPressed: _save,
|
||||
child: const Text('Save'),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user