From 09e25641838344b7e9f2037a2aaa6818d0d1d7cb Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Tue, 4 Feb 2025 13:29:09 +0400 Subject: [PATCH 1/3] add disabled state to ButtonContentWidget, When disabled, the entire button becomes opaque --- .../widgets/button_content_widget.dart | 89 ++++++++++--------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/button_content_widget.dart b/lib/pages/spaces_management/space_model/widgets/button_content_widget.dart index a3ccad7c..2cd338e4 100644 --- a/lib/pages/spaces_management/space_model/widgets/button_content_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/button_content_widget.dart @@ -6,55 +6,64 @@ class ButtonContentWidget extends StatelessWidget { final IconData? icon; final String label; final String? svgAssets; + final bool disabled; - const ButtonContentWidget( - {Key? key, this.icon, required this.label, this.svgAssets}) - : super(key: key); + const ButtonContentWidget({ + Key? key, + this.icon, + required this.label, + this.svgAssets, + this.disabled = false, + }) : super(key: key); @override Widget build(BuildContext context) { final screenWidth = MediaQuery.of(context).size.width; - return SizedBox( - width: screenWidth * 0.25, - child: Container( - decoration: BoxDecoration( - color: ColorsManager.textFieldGreyColor, - border: Border.all( - color: ColorsManager.neutralGray, - width: 3.0, + return Opacity( + opacity: disabled ? 0.5 : 1.0, + child: SizedBox( + width: screenWidth * 0.25, + child: Container( + decoration: BoxDecoration( + color: ColorsManager.textFieldGreyColor, + border: Border.all( + color: ColorsManager.neutralGray, + width: 3.0, + ), + borderRadius: BorderRadius.circular(20), ), - borderRadius: BorderRadius.circular(20), - ), - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0), - child: Row( - children: [ - if (icon != null) - Icon( - icon, - color: ColorsManager.spaceColor, - ), - if (svgAssets != null) - Padding( - padding: const EdgeInsets.only(left: 6.0), - child: SvgPicture.asset( - svgAssets!, - width: screenWidth * 0.015, // Adjust icon size - height: screenWidth * 0.015, + child: Padding( + padding: + const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0), + child: Row( + children: [ + if (icon != null) + Icon( + icon, + color: ColorsManager.spaceColor, + ), + if (svgAssets != null) + Padding( + padding: const EdgeInsets.only(left: 6.0), + child: SvgPicture.asset( + svgAssets!, + width: screenWidth * 0.015, // Adjust icon size + height: screenWidth * 0.015, + ), + ), + const SizedBox(width: 10), + Expanded( + child: Text( + label, + style: const TextStyle( + color: ColorsManager.blackColor, + fontSize: 16, + ), ), ), - const SizedBox(width: 10), - Expanded( - child: Text( - label, - style: const TextStyle( - color: ColorsManager.blackColor, - fontSize: 16, - ), - ), - ), - ], + ], + ), ), ), ), From 1fa33a271fd62846f0fd584fa64c8f27a4cc0017 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Tue, 4 Feb 2025 13:46:11 +0400 Subject: [PATCH 2/3] added disabled space model button on adding tags and subspace, vice versa --- .../widgets/dialogs/create_space_dialog.dart | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart b/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart index cd5ce4a5..59b870e5 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart @@ -95,6 +95,10 @@ class CreateSpaceDialogState extends State { @override Widget build(BuildContext context) { + bool isSpaceModelDisabled = (tags != null && tags!.isNotEmpty || + subspaces != null && subspaces!.isNotEmpty); + bool isTagsAndSubspaceModelDisabled = (selectedSpaceModel != null); + final screenWidth = MediaQuery.of(context).size.width; return AlertDialog( title: widget.isEdit @@ -240,11 +244,14 @@ class CreateSpaceDialogState extends State { padding: EdgeInsets.zero, ), onPressed: () { - _showLinkSpaceModelDialog(context); + isSpaceModelDisabled + ? null + : _showLinkSpaceModelDialog(context); }, - child: const ButtonContentWidget( + child: ButtonContentWidget( svgAssets: Assets.link, label: 'Link a space model', + disabled: isSpaceModelDisabled, ), ) : Container( @@ -333,12 +340,15 @@ class CreateSpaceDialogState extends State { overlayColor: ColorsManager.transparentColor, ), onPressed: () async { - _showSubSpaceDialog(context, enteredName, [], - false, widget.products, subspaces); + isTagsAndSubspaceModelDisabled + ? null + : _showSubSpaceDialog(context, enteredName, + [], false, widget.products, subspaces); }, - child: const ButtonContentWidget( + child: ButtonContentWidget( icon: Icons.add, label: 'Create Sub Space', + disabled: isTagsAndSubspaceModelDisabled, ), ) : SizedBox( @@ -492,19 +502,22 @@ class CreateSpaceDialogState extends State { ) : TextButton( onPressed: () { - _showTagCreateDialog( - context, - enteredName, - widget.isEdit, - widget.products, - ); + isTagsAndSubspaceModelDisabled + ? null + : _showTagCreateDialog( + context, + enteredName, + widget.isEdit, + widget.products, + ); }, style: TextButton.styleFrom( padding: EdgeInsets.zero, ), - child: const ButtonContentWidget( + child: ButtonContentWidget( icon: Icons.add, label: 'Add Devices', + disabled: isTagsAndSubspaceModelDisabled, )) ], ), From d5fcbe2601dbbd6de04d9da0167629c58be5bfe0 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Tue, 4 Feb 2025 14:15:39 +0400 Subject: [PATCH 3/3] added edit space sibling conflict --- .../widgets/dialogs/create_space_dialog.dart | 24 ++------------ .../helper/space_helper.dart | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart b/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart index 59b870e5..f3df1637 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart @@ -12,6 +12,7 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/icon_selection_dialog.dart'; import 'package:syncrow_web/pages/spaces_management/assign_tag/views/assign_tag_dialog.dart'; import 'package:syncrow_web/pages/spaces_management/create_subspace/views/create_subspace_model_dialog.dart'; +import 'package:syncrow_web/pages/spaces_management/helper/space_helper.dart'; import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart'; import 'package:syncrow_web/pages/spaces_management/link_space_model/view/link_space_model_dialog.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart'; @@ -177,7 +178,7 @@ class CreateSpaceDialogState extends State { isNameFieldInvalid = value.isEmpty; if (!isNameFieldInvalid) { - if (_isNameConflict(value)) { + if (SpaceHelper.isNameConflict(value, widget.parentSpace, widget.editSpace)) { isNameFieldExist = true; isOkButtonEnabled = false; } else { @@ -591,26 +592,7 @@ class CreateSpaceDialogState extends State { ); } - bool _isNameConflict(String value) { - final parentSpace = widget.parentSpace; - final editSpace = widget.editSpace; - final siblings = parentSpace?.children - .where((child) => child.uuid != editSpace?.uuid) - .toList() ?? - []; - final siblingConflict = siblings.any((child) => child.name == value); - final parentConflict = - parentSpace?.name == value && parentSpace?.uuid != editSpace?.uuid; - final parentOfEditSpaceConflict = editSpace?.parent?.name == value && - editSpace?.parent?.uuid != editSpace?.uuid; - final childConflict = - editSpace?.children.any((child) => child.name == value) ?? false; - return siblingConflict || - parentConflict || - parentOfEditSpaceConflict || - childConflict; - } - + void _showLinkSpaceModelDialog(BuildContext context) { showDialog( context: context, diff --git a/lib/pages/spaces_management/helper/space_helper.dart b/lib/pages/spaces_management/helper/space_helper.dart index c316106e..126306cd 100644 --- a/lib/pages/spaces_management/helper/space_helper.dart +++ b/lib/pages/spaces_management/helper/space_helper.dart @@ -58,4 +58,37 @@ class SpaceHelper { ?.any((child) => child.internalId == space.internalId) == true; } + + static bool isNameConflict( + String value, SpaceModel? parentSpace, SpaceModel? editSpace) { + final siblings = parentSpace?.children + .where((child) => child.internalId != editSpace?.internalId) + .toList() ?? + []; + + final editSiblings = editSpace?.parent?.children + .where((child) => child.internalId != editSpace.internalId) + .toList() ?? + []; + + final editSiblingConflict = + editSiblings.any((child) => child.name == value); + + final siblingConflict = siblings.any((child) => child.name == value); + + final parentConflict = parentSpace?.name == value && + parentSpace?.internalId != editSpace?.internalId; + + final parentOfEditSpaceConflict = editSpace?.parent?.name == value && + editSpace?.parent?.internalId != editSpace?.internalId; + + final childConflict = + editSpace?.children.any((child) => child.name == value) ?? false; + + return siblingConflict || + parentConflict || + editSiblingConflict || + parentOfEditSpaceConflict || + childConflict; + } }