mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-15 09:45:25 +00:00
validity for space name
This commit is contained in:
@ -331,6 +331,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
products: widget.products,
|
products: widget.products,
|
||||||
name: space.name,
|
name: space.name,
|
||||||
icon: space.icon,
|
icon: space.icon,
|
||||||
|
editSpace: space,
|
||||||
isEdit: true,
|
isEdit: true,
|
||||||
selectedProducts: space.selectedProducts,
|
selectedProducts: space.selectedProducts,
|
||||||
onCreateSpace: (String name, String icon,
|
onCreateSpace: (String name, String icon,
|
||||||
|
@ -18,6 +18,7 @@ class CreateCommunityDialog extends StatefulWidget {
|
|||||||
class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
||||||
String enteredName = '';
|
String enteredName = '';
|
||||||
bool isNameFieldExist = false;
|
bool isNameFieldExist = false;
|
||||||
|
bool isNameEmpty = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -63,10 +64,15 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
|||||||
TextField(
|
TextField(
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
enteredName = value.trim(); // Trim whitespace
|
enteredName = value.trim();
|
||||||
isNameFieldExist = widget.communities.any(
|
isNameFieldExist = widget.communities.any(
|
||||||
(community) => community.name == enteredName,
|
(community) => community.name == enteredName,
|
||||||
);
|
);
|
||||||
|
if (value.isEmpty) {
|
||||||
|
isNameEmpty = true;
|
||||||
|
} else {
|
||||||
|
isNameEmpty = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
@ -83,7 +89,7 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
|||||||
),
|
),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: isNameFieldExist
|
color: isNameFieldExist || isNameEmpty
|
||||||
? ColorsManager.red
|
? ColorsManager.red
|
||||||
: ColorsManager.boxColor,
|
: ColorsManager.boxColor,
|
||||||
width: 1),
|
width: 1),
|
||||||
@ -91,16 +97,15 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
|||||||
),
|
),
|
||||||
enabledBorder: OutlineInputBorder(
|
enabledBorder: OutlineInputBorder(
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: isNameFieldExist
|
color: isNameFieldExist || isNameEmpty
|
||||||
? ColorsManager.red
|
? ColorsManager.red
|
||||||
: ColorsManager.boxColor,
|
: ColorsManager.boxColor, width: 1),
|
||||||
width: 1),
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
focusedBorder: OutlineInputBorder(
|
focusedBorder: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: isNameFieldExist
|
color: isNameFieldExist || isNameEmpty
|
||||||
? ColorsManager.red
|
? ColorsManager.red
|
||||||
: ColorsManager.boxColor,
|
: ColorsManager.boxColor,
|
||||||
width: 1),
|
width: 1),
|
||||||
@ -118,19 +123,28 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
|||||||
?.copyWith(color: ColorsManager.red),
|
?.copyWith(color: ColorsManager.red),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (isNameEmpty)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 8.0),
|
||||||
|
child: Text(
|
||||||
|
'*Name should not be empty.',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodySmall
|
||||||
|
?.copyWith(color: ColorsManager.red),
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
// Action buttons
|
// Action buttons
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Expanded(
|
|
||||||
child: CancelButton(
|
child: CancelButton(
|
||||||
label: 'Cancel',
|
label: 'Cancel',
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: DefaultButton(
|
child: DefaultButton(
|
||||||
@ -143,7 +157,7 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
|||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
backgroundColor: isNameFieldExist || enteredName.isEmpty
|
backgroundColor: isNameFieldExist || isNameEmpty
|
||||||
? ColorsManager.lightGrayColor
|
? ColorsManager.lightGrayColor
|
||||||
: ColorsManager.secondaryColor,
|
: ColorsManager.secondaryColor,
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
|
@ -13,13 +13,15 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
|||||||
import 'package:syncrow_web/utils/constants/space_icon_const.dart';
|
import 'package:syncrow_web/utils/constants/space_icon_const.dart';
|
||||||
|
|
||||||
class CreateSpaceDialog extends StatefulWidget {
|
class CreateSpaceDialog extends StatefulWidget {
|
||||||
final Function(String, String, List<SelectedProduct> selectedProducts) onCreateSpace;
|
final Function(String, String, List<SelectedProduct> selectedProducts)
|
||||||
|
onCreateSpace;
|
||||||
final List<ProductModel>? products;
|
final List<ProductModel>? products;
|
||||||
final String? name;
|
final String? name;
|
||||||
final String? icon;
|
final String? icon;
|
||||||
final bool isEdit;
|
final bool isEdit;
|
||||||
final List<SelectedProduct> selectedProducts;
|
final List<SelectedProduct> selectedProducts;
|
||||||
final SpaceModel? parentSpace;
|
final SpaceModel? parentSpace;
|
||||||
|
final SpaceModel? editSpace;
|
||||||
|
|
||||||
const CreateSpaceDialog(
|
const CreateSpaceDialog(
|
||||||
{super.key,
|
{super.key,
|
||||||
@ -29,6 +31,7 @@ class CreateSpaceDialog extends StatefulWidget {
|
|||||||
this.name,
|
this.name,
|
||||||
this.icon,
|
this.icon,
|
||||||
this.isEdit = false,
|
this.isEdit = false,
|
||||||
|
this.editSpace,
|
||||||
this.selectedProducts = const []});
|
this.selectedProducts = const []});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -49,8 +52,10 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
selectedIcon = widget.icon ?? Assets.location;
|
selectedIcon = widget.icon ?? Assets.location;
|
||||||
nameController = TextEditingController(text: widget.name ?? '');
|
nameController = TextEditingController(text: widget.name ?? '');
|
||||||
selectedProducts = widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
|
selectedProducts =
|
||||||
isOkButtonEnabled = enteredName.isNotEmpty || nameController.text.isNotEmpty;
|
widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
|
||||||
|
isOkButtonEnabled =
|
||||||
|
enteredName.isNotEmpty || nameController.text.isNotEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -59,7 +64,9 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
final screenWidth = MediaQuery.of(context).size.width;
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: widget.isEdit ? const Text('Edit Space') : const Text('Create New Space'),
|
title: widget.isEdit
|
||||||
|
? const Text('Edit Space')
|
||||||
|
: const Text('Create New Space'),
|
||||||
backgroundColor: ColorsManager.whiteColors,
|
backgroundColor: ColorsManager.whiteColors,
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
width: screenWidth * 0.5, // Limit dialog width
|
width: screenWidth * 0.5, // Limit dialog width
|
||||||
@ -126,11 +133,17 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
isNameFieldInvalid = value.isEmpty;
|
isNameFieldInvalid = value.isEmpty;
|
||||||
|
|
||||||
if (!isNameFieldInvalid) {
|
if (!isNameFieldInvalid) {
|
||||||
if (widget.parentSpace?.children
|
if ((widget.parentSpace?.children.any(
|
||||||
.any((child) => child.name == value) ??
|
(child) => child.name == value) ??
|
||||||
false) {
|
false) ||
|
||||||
|
(widget.parentSpace?.name == value) ||
|
||||||
|
(widget.editSpace?.children.any(
|
||||||
|
(child) => child.name == value) ??
|
||||||
|
false)) {
|
||||||
isNameFieldExist = true;
|
isNameFieldExist = true;
|
||||||
|
isOkButtonEnabled = false;
|
||||||
} else {
|
} else {
|
||||||
|
isNameFieldExist = false;
|
||||||
isOkButtonEnabled = true;
|
isOkButtonEnabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,7 +231,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
padding: const EdgeInsets.only(left: 6.0),
|
padding: const EdgeInsets.only(left: 6.0),
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
Assets.addIcon,
|
Assets.addIcon,
|
||||||
width: screenWidth * 0.015, // Adjust icon size
|
width: screenWidth *
|
||||||
|
0.015, // Adjust icon size
|
||||||
height: screenWidth * 0.015,
|
height: screenWidth * 0.015,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -226,8 +240,11 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
Flexible(
|
Flexible(
|
||||||
child: Text(
|
child: Text(
|
||||||
'Add devices / Assign a space model',
|
'Add devices / Assign a space model',
|
||||||
overflow: TextOverflow.ellipsis, // Prevent overflow
|
overflow: TextOverflow
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
.ellipsis, // Prevent overflow
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -262,16 +279,20 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
String newName = enteredName.isNotEmpty ? enteredName : (widget.name ?? '');
|
String newName = enteredName.isNotEmpty
|
||||||
|
? enteredName
|
||||||
|
: (widget.name ?? '');
|
||||||
if (newName.isNotEmpty) {
|
if (newName.isNotEmpty) {
|
||||||
widget.onCreateSpace(newName, selectedIcon, selectedProducts);
|
widget.onCreateSpace(
|
||||||
|
newName, selectedIcon, selectedProducts);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
backgroundColor:
|
backgroundColor: isOkButtonEnabled
|
||||||
isOkButtonEnabled ? ColorsManager.secondaryColor : ColorsManager.grayColor,
|
? ColorsManager.secondaryColor
|
||||||
|
: ColorsManager.grayColor,
|
||||||
foregroundColor: ColorsManager.whiteColors,
|
foregroundColor: ColorsManager.whiteColors,
|
||||||
child: const Text('OK'),
|
child: const Text('OK'),
|
||||||
),
|
),
|
||||||
@ -318,7 +339,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
children: [
|
children: [
|
||||||
for (var i = 0; i < selectedProducts.length; i++) ...[
|
for (var i = 0; i < selectedProducts.length; i++) ...[
|
||||||
HoverableButton(
|
HoverableButton(
|
||||||
iconPath: _mapIconToProduct(selectedProducts[i].productId, products),
|
iconPath:
|
||||||
|
_mapIconToProduct(selectedProducts[i].productId, products),
|
||||||
text: 'x${selectedProducts[i].count}',
|
text: 'x${selectedProducts[i].count}',
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -328,7 +350,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (i < selectedProducts.length - 1)
|
if (i < selectedProducts.length - 1)
|
||||||
const SizedBox(width: 2), // Add space except after the last button
|
const SizedBox(
|
||||||
|
width: 2), // Add space except after the last button
|
||||||
],
|
],
|
||||||
const SizedBox(width: 2),
|
const SizedBox(width: 2),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
@ -364,6 +387,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String _mapIconToProduct(String uuid, List<ProductModel> products) {
|
String _mapIconToProduct(String uuid, List<ProductModel> products) {
|
||||||
// Find the product with the matching UUID
|
// Find the product with the matching UUID
|
||||||
final product = products.firstWhere(
|
final product = products.firstWhere(
|
||||||
|
@ -7,7 +7,6 @@ import 'package:syncrow_web/pages/spaces_management/bloc/space_management_event.
|
|||||||
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/widgets/community_tile.dart';
|
import 'package:syncrow_web/pages/spaces_management/widgets/community_tile.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/widgets/dialogs/create_community_dialog.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/widgets/space_tile_widget.dart';
|
import 'package:syncrow_web/pages/spaces_management/widgets/space_tile_widget.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
@ -204,7 +203,6 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
|
|
||||||
Widget _buildSpaceTile(SpaceModel space, CommunityModel community) {
|
Widget _buildSpaceTile(SpaceModel space, CommunityModel community) {
|
||||||
bool isExpandedSpace = _isSpaceOrChildSelected(space);
|
bool isExpandedSpace = _isSpaceOrChildSelected(space);
|
||||||
// Check if space should be expanded
|
|
||||||
return SpaceTile(
|
return SpaceTile(
|
||||||
title: space.name,
|
title: space.name,
|
||||||
key: ValueKey(space.uuid),
|
key: ValueKey(space.uuid),
|
||||||
|
Reference in New Issue
Block a user