From 35a99ccda7c7ddc3d0654f562235ff993a02b492 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Sun, 13 Apr 2025 12:27:04 +0300 Subject: [PATCH] removed unnecessary comments from `SidebarWidget`. --- .../all_spaces/widgets/sidebar_widget.dart | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/lib/pages/spaces_management/all_spaces/widgets/sidebar_widget.dart b/lib/pages/spaces_management/all_spaces/widgets/sidebar_widget.dart index 81cec22f..2e486cc6 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/sidebar_widget.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/sidebar_widget.dart @@ -29,15 +29,14 @@ class SidebarWidget extends StatefulWidget { } class _SidebarWidgetState extends State { - String _searchQuery = ''; // Track search query + String _searchQuery = ''; String? _selectedSpaceUuid; String? _selectedId; @override void initState() { super.initState(); - _selectedId = - widget.selectedSpaceUuid; // Initialize with the passed selected space UUID + _selectedId = widget.selectedSpaceUuid; } @override @@ -50,15 +49,12 @@ class _SidebarWidgetState extends State { } } - // Function to filter communities based on the search query List _filterCommunities() { if (_searchQuery.isEmpty) { - // Reset the selected community and space UUIDs if there's no query _selectedSpaceUuid = null; return widget.communities; } - // Filter communities and expand only those that match the query return widget.communities.where((community) { final containsQueryInCommunity = community.name.toLowerCase().contains(_searchQuery.toLowerCase()); @@ -69,13 +65,12 @@ class _SidebarWidgetState extends State { }).toList(); } - // Helper function to determine if any space or its children match the search query bool _containsQuery(SpaceModel space, String query) { final matchesSpace = space.name.toLowerCase().contains(query); final matchesChildren = space.children.any( - (child) => _containsQuery(child, query)); // Recursive check for children + (child) => _containsQuery(child, query), + ); - // If the space or any of its children match the query, expand this space if (matchesSpace || matchesChildren) { _selectedSpaceUuid = space.uuid; } @@ -84,12 +79,10 @@ class _SidebarWidgetState extends State { } bool _isSpaceOrChildSelected(SpaceModel space) { - // Return true if the current space or any of its child spaces is selected if (_selectedSpaceUuid == space.uuid) { return true; } - // Recursively check if any child spaces match the query for (var child in space.children) { if (_isSpaceOrChildSelected(child)) { return true; @@ -107,11 +100,9 @@ class _SidebarWidgetState extends State { width: 300, decoration: subSectionContainerDecoration, child: Column( - mainAxisSize: - MainAxisSize.min, // Ensures the Column only takes necessary height + mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - // Communities title with the add button Container( decoration: subSectionContainerDecoration, padding: const EdgeInsets.all(16.0), @@ -143,7 +134,6 @@ class _SidebarWidgetState extends State { ], ), ), - // Search bar CustomSearchBar( onSearchChanged: (query) { setState(() { @@ -152,7 +142,6 @@ class _SidebarWidgetState extends State { }, ), const SizedBox(height: 16), - // Community list Expanded( child: ListView( children: filteredCommunities @@ -185,7 +174,7 @@ class _SidebarWidgetState extends State { onItemSelected: () { setState(() { _selectedId = community.uuid; - _selectedSpaceUuid = null; // Update the selected community + _selectedSpaceUuid = null; }); context.read().add(CommunitySelectedEvent()); @@ -231,7 +220,7 @@ class _SidebarWidgetState extends State { ? space.children .map((childSpace) => _buildSpaceTile(childSpace, community)) .toList() - : [], // Recursively render child spaces if available + : [], )); } }