104 lines
3.1 KiB
Dart
104 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../domain/models/floor.dart';
|
|
|
|
class RoomEditSheet extends StatefulWidget {
|
|
const RoomEditSheet({
|
|
super.key,
|
|
required this.room,
|
|
required this.onSaved,
|
|
});
|
|
|
|
final Room room;
|
|
final void Function(String name, double width, double height) onSaved;
|
|
|
|
@override
|
|
State<RoomEditSheet> createState() => _RoomEditSheetState();
|
|
}
|
|
|
|
class _RoomEditSheetState extends State<RoomEditSheet> {
|
|
late final TextEditingController _nameCtrl;
|
|
late final TextEditingController _widthCtrl;
|
|
late final TextEditingController _heightCtrl;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_nameCtrl = TextEditingController(text: widget.room.name);
|
|
_widthCtrl = TextEditingController(text: widget.room.width.toString());
|
|
_heightCtrl = TextEditingController(text: widget.room.height.toString());
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_nameCtrl.dispose();
|
|
_widthCtrl.dispose();
|
|
_heightCtrl.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
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;
|
|
|
|
widget.onSaved(name, width, height);
|
|
Navigator.of(context).pop();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final insets = MediaQuery.viewInsetsOf(context);
|
|
return Padding(
|
|
padding: EdgeInsets.fromLTRB(24, 24, 24, 24 + insets.bottom),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text('Edit room', style: Theme.of(context).textTheme.titleMedium),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: _nameCtrl,
|
|
decoration: const InputDecoration(labelText: 'Name'),
|
|
autofocus: true,
|
|
textInputAction: TextInputAction.next,
|
|
),
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: TextField(
|
|
controller: _widthCtrl,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Width', suffixText: 'm'),
|
|
keyboardType:
|
|
const TextInputType.numberWithOptions(decimal: true),
|
|
textInputAction: TextInputAction.next,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: TextField(
|
|
controller: _heightCtrl,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Height', suffixText: 'm'),
|
|
keyboardType:
|
|
const TextInputType.numberWithOptions(decimal: true),
|
|
textInputAction: TextInputAction.done,
|
|
onSubmitted: (_) => _save(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 24),
|
|
FilledButton(
|
|
onPressed: _save,
|
|
child: const Text('Save'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|