mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
added validation to create space
This commit is contained in:
@ -36,6 +36,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
String enteredName = '';
|
||||
List<SelectedProduct> selectedProducts = [];
|
||||
late TextEditingController nameController;
|
||||
bool isOkButtonEnabled = false;
|
||||
bool isNameFieldInvalid = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -43,6 +45,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
selectedIcon = widget.icon ?? Assets.location;
|
||||
nameController = TextEditingController(text: widget.name ?? '');
|
||||
selectedProducts = widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
|
||||
isOkButtonEnabled = enteredName.isNotEmpty || widget.name!.isNotEmpty;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -113,6 +116,14 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
controller: nameController,
|
||||
onChanged: (value) {
|
||||
enteredName = value;
|
||||
setState(() {
|
||||
if (value.isNotEmpty) {
|
||||
isOkButtonEnabled = true;
|
||||
isNameFieldInvalid = false;
|
||||
} else {
|
||||
isOkButtonEnabled = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
style: const TextStyle(color: Colors.black),
|
||||
decoration: InputDecoration(
|
||||
@ -126,8 +137,9 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
fillColor: ColorsManager.boxColor,
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(
|
||||
color: ColorsManager.boxColor,
|
||||
borderSide: BorderSide(
|
||||
color:
|
||||
isNameFieldInvalid ? ColorsManager.red : ColorsManager.boxColor,
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
@ -140,6 +152,17 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (isNameFieldInvalid)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(
|
||||
'*Space name should not be empty.',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall
|
||||
?.copyWith(color: ColorsManager.red),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (selectedProducts.isNotEmpty)
|
||||
_buildSelectedProductsButtons(widget.products ?? [])
|
||||
@ -210,13 +233,22 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
Expanded(
|
||||
child: DefaultButton(
|
||||
onPressed: () {
|
||||
String newName = enteredName.isNotEmpty ? enteredName : (widget.name ?? '');
|
||||
if (newName.isNotEmpty) {
|
||||
widget.onCreateSpace(newName, selectedIcon, selectedProducts);
|
||||
Navigator.of(context).pop();
|
||||
if (enteredName.trim().isEmpty || widget.name!.isEmpty) {
|
||||
setState(() {
|
||||
isNameFieldInvalid = true;
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
String newName = enteredName.isNotEmpty ? enteredName : (widget.name ?? '');
|
||||
if (newName.isNotEmpty) {
|
||||
widget.onCreateSpace(newName, selectedIcon, selectedProducts);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
backgroundColor: ColorsManager.secondaryColor,
|
||||
borderRadius: 10,
|
||||
backgroundColor:
|
||||
isOkButtonEnabled ? ColorsManager.secondaryColor : ColorsManager.grayColor,
|
||||
foregroundColor: ColorsManager.whiteColors,
|
||||
child: const Text('OK'),
|
||||
),
|
||||
|
Reference in New Issue
Block a user