mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
added validity for reusing space name in same layer
This commit is contained in:
@ -270,6 +270,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
builder: (BuildContext context) {
|
||||
return CreateSpaceDialog(
|
||||
products: widget.products,
|
||||
parentSpace: parentIndex != null? spaces[parentIndex] : null,
|
||||
onCreateSpace: (String name, String icon, List<SelectedProduct> selectedProducts) {
|
||||
setState(() {
|
||||
// Set the first space in the center or use passed position
|
||||
|
@ -4,6 +4,7 @@ import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/selected_product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/add_device_type_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/dialogs/icon_selection_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/hoverable_button.dart';
|
||||
@ -18,9 +19,11 @@ class CreateSpaceDialog extends StatefulWidget {
|
||||
final String? icon;
|
||||
final bool isEdit;
|
||||
final List<SelectedProduct> selectedProducts;
|
||||
final SpaceModel? parentSpace;
|
||||
|
||||
const CreateSpaceDialog(
|
||||
{super.key,
|
||||
this.parentSpace,
|
||||
required this.onCreateSpace,
|
||||
this.products,
|
||||
this.name,
|
||||
@ -39,6 +42,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
late TextEditingController nameController;
|
||||
bool isOkButtonEnabled = false;
|
||||
bool isNameFieldInvalid = false;
|
||||
bool isNameFieldExist = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -47,7 +51,6 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
nameController = TextEditingController(text: widget.name ?? '');
|
||||
selectedProducts = widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
|
||||
isOkButtonEnabled = enteredName.isNotEmpty || nameController.text.isNotEmpty;
|
||||
isNameFieldInvalid = nameController.text.isEmpty;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -116,14 +119,20 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
TextField(
|
||||
controller: nameController,
|
||||
onChanged: (value) {
|
||||
enteredName = value;
|
||||
enteredName = value.trim();
|
||||
setState(() {
|
||||
if (value.isNotEmpty) {
|
||||
isOkButtonEnabled = true;
|
||||
isNameFieldInvalid = false;
|
||||
} else {
|
||||
isNameFieldInvalid = true;
|
||||
isNameFieldExist = false;
|
||||
isOkButtonEnabled = false;
|
||||
isNameFieldInvalid = value.isEmpty;
|
||||
|
||||
if (!isNameFieldInvalid) {
|
||||
if (widget.parentSpace?.children
|
||||
.any((child) => child.name == value) ??
|
||||
false) {
|
||||
isNameFieldExist = true;
|
||||
} else {
|
||||
isOkButtonEnabled = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -140,8 +149,9 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(
|
||||
color:
|
||||
isNameFieldInvalid ? ColorsManager.red : ColorsManager.boxColor,
|
||||
color: isNameFieldInvalid || isNameFieldExist
|
||||
? ColorsManager.red
|
||||
: ColorsManager.boxColor,
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
@ -165,6 +175,17 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
?.copyWith(color: ColorsManager.red),
|
||||
),
|
||||
),
|
||||
if (isNameFieldExist)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(
|
||||
'*Name already exist',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall
|
||||
?.copyWith(color: ColorsManager.red),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (selectedProducts.isNotEmpty)
|
||||
_buildSelectedProductsButtons(widget.products ?? [])
|
||||
|
Reference in New Issue
Block a user