sidebar widget

This commit is contained in:
hannathkadher
2024-09-26 14:49:19 +04:00
parent b40998558e
commit fe3525d255
4 changed files with 67 additions and 30 deletions

View File

@ -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,

View File

@ -0,0 +1,6 @@
class Community {
final String name;
final List<Community>? children; // Sub-communities
Community({required this.name, this.children});
}

View File

@ -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<SidebarWidget> {
String? _expandedTile;
String _searchQuery = ''; // Track search query
// List of all communities
final List<Community> _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<SidebarWidget> {
widget.onCommunitySelected?.call(title);
}
List<Community> _filterCommunities() {
if (_searchQuery.isEmpty) {
return _communities;
}
return _communities
.where((community) =>
community.name.toLowerCase().contains(_searchQuery.toLowerCase()))
.toList();
}
@override
Widget build(BuildContext context) {
List<Community> filteredCommunities = _filterCommunities();
return Container(
width: 300,
decoration: subSectionContainerDecoration,
@ -69,39 +95,41 @@ class _SidebarWidgetState extends State<SidebarWidget> {
),
),
// 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
);
}
}

View File

@ -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();
}