From 8b7de7c8fd6550f0a24b3e2cefcc45f363d02e1e Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Thu, 21 Nov 2024 21:05:49 +0400 Subject: [PATCH] deselect on outside --- .../widgets/device_search_filters.dart | 1 - .../widgets/community_structure_widget.dart | 57 ++++++++++++++----- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart b/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart index 71974156..c68f9485 100644 --- a/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart +++ b/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart @@ -4,7 +4,6 @@ import 'package:syncrow_web/pages/common/text_field/custom_text_field.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_managment_bloc.dart'; import 'package:syncrow_web/pages/common/buttons/search_reset_buttons.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; -import 'package:syncrow_web/utils/style.dart'; class DeviceSearchFilters extends StatefulWidget { const DeviceSearchFilters({super.key}); diff --git a/lib/pages/spaces_management/widgets/community_structure_widget.dart b/lib/pages/spaces_management/widgets/community_structure_widget.dart index c8f8b3f1..4f609827 100644 --- a/lib/pages/spaces_management/widgets/community_structure_widget.dart +++ b/lib/pages/spaces_management/widgets/community_structure_widget.dart @@ -94,10 +94,13 @@ class _CommunityStructureAreaState extends State { @override Widget build(BuildContext context) { final visibleSpaces = flattenSpaces(widget.spaces); - final visibleConnections = createConnections(widget.spaces); Size screenSize = MediaQuery.of(context).size; return Expanded( + child: GestureDetector( + onTap: () { + _deselectSpace(); + }, child: Container( decoration: const BoxDecoration( border: Border( @@ -147,17 +150,22 @@ class _CommunityStructureAreaState extends State { _updateNodePosition(entry.value, newPosition); }, buildSpaceContainer: (int index) { - return SpaceContainerWidget( - index: index, - onDoubleTap: () { - _showEditSpaceDialog(visibleSpaces[index]); - }, - onTap: () { - _selectSpace(visibleSpaces[index]); - }, - icon: visibleSpaces[index].icon ?? '', - name: visibleSpaces[index].name, - ); + final bool isHighlighted = + _isHighlightedSpace(visibleSpaces[index]); + + return Opacity( + opacity: isHighlighted ? 1.0 : 0.3, + child: SpaceContainerWidget( + index: index, + onDoubleTap: () { + _showEditSpaceDialog(visibleSpaces[index]); + }, + onTap: () { + _selectSpace(visibleSpaces[index]); + }, + icon: visibleSpaces[index].icon ?? '', + name: visibleSpaces[index].name, + )); }, ), ), @@ -178,7 +186,7 @@ class _CommunityStructureAreaState extends State { ], ), ), - ); + )); } Widget _buildHeader() { @@ -570,4 +578,27 @@ class _CommunityStructureAreaState extends State { widget.onSpaceSelected!(space); } } + + bool _isHighlightedSpace(SpaceModel space) { + if (widget.selectedSpace == null) return true; + if (space == widget.selectedSpace) return true; + + if (widget.selectedSpace?.parent?.name == space.name && + widget.selectedSpace?.parent?.position == space.position) return true; + if (widget.selectedSpace?.children.contains(space) == true) return true; + + return false; // Otherwise, reduce opacity + } + + void _deselectSpace() { + if (widget.selectedSpace != null) { + setState(() { + widget.selectedSpace = null; + }); + + if (widget.onSpaceSelected != null) { + widget.onSpaceSelected!(null); // Notify parent that no space is selected + } + } + } }