mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
136 lines
4.2 KiB
Dart
136 lines
4.2 KiB
Dart
import 'package:flutter/material.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';
|
|
import 'package:syncrow_web/utils/style.dart';
|
|
|
|
class SidebarWidget extends StatefulWidget {
|
|
final Function(String)? onCommunitySelected;
|
|
|
|
SidebarWidget({this.onCommunitySelected});
|
|
|
|
@override
|
|
_SidebarWidgetState createState() => _SidebarWidgetState();
|
|
}
|
|
|
|
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) {
|
|
setState(() {
|
|
_expandedTile = expanded ? title : null;
|
|
});
|
|
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,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Communities title with the add button
|
|
Container(
|
|
decoration: subSectionContainerDecoration,
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
'Communities',
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
// Handle add button action
|
|
},
|
|
child: Container(
|
|
width: 30,
|
|
height: 30,
|
|
decoration: const BoxDecoration(
|
|
color: ColorsManager.whiteColors,
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Center(
|
|
child: SvgPicture.asset(
|
|
Assets.roundedAddIcon,
|
|
width: 24,
|
|
height: 24,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// Search bar
|
|
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.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
|
|
);
|
|
}
|
|
}
|