diff --git a/lib/common/custom_expansion_tile.dart b/lib/common/custom_expansion_tile.dart index e5dc2e16..a6412b3c 100644 --- a/lib/common/custom_expansion_tile.dart +++ b/lib/common/custom_expansion_tile.dart @@ -84,9 +84,7 @@ class CustomExpansionTileState extends State { }); }, child: Icon( - _isExpanded - ? Icons.keyboard_arrow_down - : Icons.keyboard_arrow_right, + _isExpanded ? Icons.keyboard_arrow_down : Icons.keyboard_arrow_right, color: Colors.grey, size: 16.0, // Adjusted size for better alignment ), @@ -95,7 +93,6 @@ class CustomExpansionTileState extends State { Expanded( child: GestureDetector( onTap: () { - // Triggerxq the onItemSelected callback when the name is tapped if (widget.onItemSelected != null) { widget.onItemSelected!(); } @@ -106,8 +103,7 @@ class CustomExpansionTileState extends State { style: TextStyle( color: widget.isSelected ? Colors.black // Change color to black when selected - : ColorsManager - .lightGrayColor, // Gray when not selected + : ColorsManager.lightGrayColor, // Gray when not selected fontWeight: FontWeight.w400, ), ), @@ -116,9 +112,7 @@ class CustomExpansionTileState extends State { ], ), // The expanded section (children) that shows when the tile is expanded - if (_isExpanded && - widget.children != null && - widget.children!.isNotEmpty) + if (_isExpanded && widget.children != null && widget.children!.isNotEmpty) Padding( padding: const EdgeInsets.only(left: 48.0), // Indented children child: Column( diff --git a/lib/pages/spaces_management/widgets/sidebar_widget.dart b/lib/pages/spaces_management/widgets/sidebar_widget.dart index f50663b3..58782f6b 100644 --- a/lib/pages/spaces_management/widgets/sidebar_widget.dart +++ b/lib/pages/spaces_management/widgets/sidebar_widget.dart @@ -29,6 +29,7 @@ class _SidebarWidgetState extends State { String _searchQuery = ''; // Track search query String? _selectedCommunityUuid; String? _selectedSpaceUuid; + String? _selectedId; @override void initState() { @@ -173,15 +174,19 @@ class _SidebarWidgetState extends State { Widget _buildCommunityTile(CommunityModel community) { bool hasChildren = community.spaces.isNotEmpty; - bool isSelectedCommunity = - _selectedCommunityUuid == community.uuid; // Check if this community is selected + bool isSelectedCommunity = _selectedCommunityUuid == community.uuid; + + // Check if this community is selected return CommunityTile( title: community.name, - isSelected: isSelectedCommunity, + key: ValueKey(community.uuid), + isSelected: _selectedId == community.uuid, isExpanded: false, onItemSelected: () { setState(() { - _selectedSpaceUuid = community.uuid; // Update the selected community + _selectedId = community.uuid; + _selectedCommunityUuid = community.uuid; + _selectedSpaceUuid = null; // Update the selected community }); if (widget.onCommunitySelected != null) { @@ -198,21 +203,26 @@ class _SidebarWidgetState extends State { } Widget _buildSpaceTile(SpaceModel space, CommunityModel community) { - bool isSelectedSpace = _isSpaceOrChildSelected(space); // Check if space should be expanded + bool isExpandedSpace = _isSpaceOrChildSelected(space); + bool isSelectedSpace = _selectedSpaceUuid == space.uuid; +// Check if space should be expanded return SpaceTile( title: space.name, - isSelected: isSelectedSpace, - initiallyExpanded: isSelectedSpace, + key: ValueKey(space.uuid), + isSelected: _selectedId == space.uuid, + initiallyExpanded: isExpandedSpace, onExpansionChanged: (bool expanded) { _handleExpansionChange(space.uuid ?? '', expanded); }, onItemSelected: () { - if (widget.onCommunitySelected != null || widget.onSpaceSelected != null) { - widget.onCommunitySelected!(community); // Pass the entire community - } - + setState(() { + _selectedId = space.uuid; + _selectedSpaceUuid = space.uuid; + _selectedCommunityUuid = community.uuid; // Update selected community + }); + print(_selectedSpaceUuid); if (widget.onSpaceSelected != null) { - widget.onSpaceSelected!(space); // Pass the entire community + widget.onSpaceSelected!(space); } }, children: space.children.isNotEmpty diff --git a/lib/pages/spaces_management/widgets/space_tile_widget.dart b/lib/pages/spaces_management/widgets/space_tile_widget.dart index 95311b9a..80753f9d 100644 --- a/lib/pages/spaces_management/widgets/space_tile_widget.dart +++ b/lib/pages/spaces_management/widgets/space_tile_widget.dart @@ -36,7 +36,7 @@ class _SpaceTileState extends State { @override Widget build(BuildContext context) { return CustomExpansionTile( - isSelected: false, + isSelected: widget.isSelected, title: widget.title, initiallyExpanded: _isExpanded, onItemSelected: widget.onItemSelected,