mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-25 14:19:40 +00:00
Add DuplicateSpaceDialog
widget for user interaction in duplicate space management.
This commit is contained in:
@ -0,0 +1,68 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/duplicate_space/presentation/widgets/duplicate_space_text_field.dart';
|
||||||
|
|
||||||
|
class DuplicateSpaceDialog extends StatefulWidget {
|
||||||
|
const DuplicateSpaceDialog({
|
||||||
|
required this.initialName,
|
||||||
|
required this.onSubmit,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String initialName;
|
||||||
|
final void Function(String) onSubmit;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<DuplicateSpaceDialog> createState() => _DuplicateSpaceDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DuplicateSpaceDialogState extends State<DuplicateSpaceDialog> {
|
||||||
|
late final TextEditingController _nameController;
|
||||||
|
bool _isNameValid = true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_nameController = TextEditingController(text: '${widget.initialName}(1)');
|
||||||
|
_nameController.addListener(_validateName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _validateName() => setState(
|
||||||
|
() => _isNameValid = _nameController.text.trim() != widget.initialName,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_nameController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const SelectableText('Duplicate Space'),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
spacing: 16,
|
||||||
|
children: [
|
||||||
|
const SelectableText('Enter a new name for the duplicated space:'),
|
||||||
|
DuplicateSpaceTextField(
|
||||||
|
nameController: _nameController,
|
||||||
|
isNameValid: _isNameValid,
|
||||||
|
initialName: widget.initialName,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: Navigator.of(context).pop,
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed:
|
||||||
|
_isNameValid ? () => widget.onSubmit(_nameController.text) : null,
|
||||||
|
child: const Text('Duplicate'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user