From fe3525d2559d899be9b64b4ded003df3298a2079 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Thu, 26 Sep 2024 14:49:19 +0400 Subject: [PATCH] sidebar widget --- lib/common/search_bar.dart | 7 +- .../model/community_model.dart | 6 ++ .../view/sidebar_widget.dart | 82 +++++++++++++------ .../view/spaces_management_page.dart | 2 +- 4 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 lib/pages/spaces_management/model/community_model.dart diff --git a/lib/common/search_bar.dart b/lib/common/search_bar.dart index 073957b2..21ac8055 100644 --- a/lib/common/search_bar.dart +++ b/lib/common/search_bar.dart @@ -6,12 +6,14 @@ import 'package:syncrow_web/utils/constants/assets.dart'; class CustomSearchBar extends StatelessWidget { final TextEditingController? controller; final String hintText; + final Function(String)? onSearchChanged; // Callback for search input changes const CustomSearchBar({ - Key? key, + super.key, this.controller, this.hintText = 'Search', - }) : super(key: key); + this.onSearchChanged, + }); @override Widget build(BuildContext context) { @@ -39,6 +41,7 @@ class CustomSearchBar extends StatelessWidget { style: const TextStyle( color: Colors.black, ), + onChanged: onSearchChanged, // Call the callback on text change decoration: InputDecoration( filled: true, fillColor: ColorsManager.textFieldGreyColor, diff --git a/lib/pages/spaces_management/model/community_model.dart b/lib/pages/spaces_management/model/community_model.dart new file mode 100644 index 00000000..5c4b1ce6 --- /dev/null +++ b/lib/pages/spaces_management/model/community_model.dart @@ -0,0 +1,6 @@ +class Community { + final String name; + final List? children; // Sub-communities + + Community({required this.name, this.children}); +} diff --git a/lib/pages/spaces_management/view/sidebar_widget.dart b/lib/pages/spaces_management/view/sidebar_widget.dart index 8572c63c..8d775672 100644 --- a/lib/pages/spaces_management/view/sidebar_widget.dart +++ b/lib/pages/spaces_management/view/sidebar_widget.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:flutter_svg/flutter_svg.dart'; +import 'package:flutter_svg/svg.dart'; import 'package:syncrow_web/common/search_bar.dart'; +import 'package:syncrow_web/pages/spaces_management/model/community_model.dart'; import 'package:syncrow_web/pages/spaces_management/view/community_tile.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; @@ -17,6 +18,19 @@ class SidebarWidget extends StatefulWidget { class _SidebarWidgetState extends State { String? _expandedTile; + String _searchQuery = ''; // Track search query + + // List of all communities + final List _communities = [ + Community(name: 'Downtown Dubai'), + Community(name: 'Dubai Creek Harbour'), + Community( + name: 'Dubai Hills Estate', + children: [ + Community(name: 'South Side'), // Nested community + ], + ), + ]; // A helper method to handle the expansion logic for CustomExpansionTile void _handleExpansionChange(String title, bool expanded) { @@ -26,8 +40,20 @@ class _SidebarWidgetState extends State { widget.onCommunitySelected?.call(title); } + List _filterCommunities() { + if (_searchQuery.isEmpty) { + return _communities; + } + return _communities + .where((community) => + community.name.toLowerCase().contains(_searchQuery.toLowerCase())) + .toList(); + } + @override Widget build(BuildContext context) { + List filteredCommunities = _filterCommunities(); + return Container( width: 300, decoration: subSectionContainerDecoration, @@ -69,39 +95,41 @@ class _SidebarWidgetState extends State { ), ), // Search bar - const CustomSearchBar(), + CustomSearchBar( + onSearchChanged: (query) { + setState(() { + _searchQuery = query; // Update search query on text change + }); + }, + ), const SizedBox(height: 16), // Community list with one item expanded at a time Expanded( - child: ListView( - children: [ - CommunityTile( - title: "Downtown Dubai", - expandedTile: _expandedTile ?? '', - onExpansionChanged: _handleExpansionChange, - ), - CommunityTile( - title: 'Dubai Creek Harbour', - expandedTile: _expandedTile ?? '', - onExpansionChanged: _handleExpansionChange, - ), - CommunityTile( - title: 'Dubai Hills Estate', - expandedTile: _expandedTile ?? '', - onExpansionChanged: _handleExpansionChange, - children: [ - CommunityTile( - title: 'South Side', - expandedTile: _expandedTile ?? '', - onExpansionChanged: _handleExpansionChange, - ), - ], - ), - ], + child: ListView.builder( + itemCount: filteredCommunities.length, + itemBuilder: (context, index) { + Community community = filteredCommunities[index]; + return _buildCommunityTile(community); + }, ), ), ], ), ); } + + Widget _buildCommunityTile(Community community) { + bool hasChildren = + community.children != null && community.children!.isNotEmpty; + return CommunityTile( + title: community.name, + expandedTile: _expandedTile ?? '', + onExpansionChanged: _handleExpansionChange, + children: hasChildren + ? community.children! + .map((child) => _buildCommunityTile(child)) + .toList() + : null, // Recursively render sub-communities + ); + } } diff --git a/lib/pages/spaces_management/view/spaces_management_page.dart b/lib/pages/spaces_management/view/spaces_management_page.dart index e5f6eedf..50fc9c3a 100644 --- a/lib/pages/spaces_management/view/spaces_management_page.dart +++ b/lib/pages/spaces_management/view/spaces_management_page.dart @@ -9,7 +9,7 @@ import 'package:syncrow_web/pages/spaces_management/view/sidebar_widget.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; -class SpaceManagementPage extends StatefulWidget { +class SpaceManagementPage extends StatefulWidget with HelperResponsiveLayout { @override SpaceManagementPageState createState() => SpaceManagementPageState(); }