mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 17:44:56 +00:00
fixed expand error
This commit is contained in:
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_web/common/custom_expansion_tile.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/model/space_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/community_tile.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/view/dialogs/create_community_dialog.dart';
|
||||
@ -11,9 +12,9 @@ import 'package:syncrow_web/utils/style.dart';
|
||||
|
||||
class SidebarWidget extends StatefulWidget {
|
||||
final Function(String)? onCommunitySelected;
|
||||
final Map<String, List<SpaceModel>> communitySpaces;
|
||||
final List<CommunityModel> communities;
|
||||
|
||||
SidebarWidget({this.onCommunitySelected, required this.communitySpaces});
|
||||
SidebarWidget({this.onCommunitySelected, required this.communities});
|
||||
|
||||
@override
|
||||
_SidebarWidgetState createState() => _SidebarWidgetState();
|
||||
@ -34,9 +35,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
builder: (context) => CreateCommunityDialog(
|
||||
onCreateCommunity: (String communityName) {
|
||||
setState(() {
|
||||
debugPrint("hello");
|
||||
|
||||
// You can update the communitySpaces map here
|
||||
// You can update the community list here when a new community is added
|
||||
});
|
||||
},
|
||||
),
|
||||
@ -44,21 +43,19 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
}
|
||||
|
||||
// Function to filter communities based on the search query
|
||||
Map<String, List<SpaceModel>> _filterCommunities() {
|
||||
List<CommunityModel> _filterCommunities() {
|
||||
if (_searchQuery.isEmpty) {
|
||||
return widget.communitySpaces;
|
||||
return widget.communities;
|
||||
}
|
||||
|
||||
// Filter communities and their spaces based on the search query
|
||||
final filteredCommunitySpaces = <String, List<SpaceModel>>{};
|
||||
widget.communitySpaces.forEach((communityName, spaces) {
|
||||
if (communityName.toLowerCase().contains(_searchQuery.toLowerCase()) ||
|
||||
spaces.any(
|
||||
(space) => _containsQuery(space, _searchQuery.toLowerCase()))) {
|
||||
filteredCommunitySpaces[communityName] = spaces;
|
||||
}
|
||||
});
|
||||
return filteredCommunitySpaces;
|
||||
return widget.communities.where((community) {
|
||||
final containsQueryInCommunity =
|
||||
community.name.toLowerCase().contains(_searchQuery.toLowerCase());
|
||||
final containsQueryInSpaces = community.spaces
|
||||
.any((space) => _containsQuery(space, _searchQuery.toLowerCase()));
|
||||
return containsQueryInCommunity || containsQueryInSpaces;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// Helper function to determine if any space or its children match the search query
|
||||
@ -128,13 +125,10 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Community list
|
||||
Flexible(
|
||||
fit: FlexFit
|
||||
.loose, // Ensure the ListView can flex but doesn't expand indefinitely
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: filteredCommunities.keys.map((communityName) {
|
||||
return _buildCommunityTile(
|
||||
communityName, filteredCommunities[communityName]!);
|
||||
children: filteredCommunities.map((community) {
|
||||
return _buildCommunityTile(community);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
@ -143,21 +137,21 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCommunityTile(String communityName, List<SpaceModel> spaces) {
|
||||
bool hasChildren = spaces.isNotEmpty;
|
||||
Widget _buildCommunityTile(CommunityModel community) {
|
||||
bool hasChildren = community.spaces.isNotEmpty;
|
||||
|
||||
debugPrint(
|
||||
'Building CommunityTile for $communityName, hasChildren: $hasChildren');
|
||||
'Building CommunityTile for ${community.name}, hasChildren: $hasChildren');
|
||||
return CommunityTile(
|
||||
title: communityName,
|
||||
isExpanded: _expandedTiles[communityName] ?? false,
|
||||
title: community.name,
|
||||
isExpanded: _expandedTiles[community.uuid] ?? false,
|
||||
onExpansionChanged: (String title, bool expanded) {
|
||||
debugPrint(
|
||||
'CommunityTile onExpansionChanged called for $title, expanded: $expanded');
|
||||
_handleExpansionChange(title, expanded);
|
||||
_handleExpansionChange(community.uuid, expanded);
|
||||
},
|
||||
children: hasChildren
|
||||
? spaces.map((space) => _buildSpaceTile(space)).toList()
|
||||
? community.spaces.map((space) => _buildSpaceTile(space)).toList()
|
||||
: null, // Render spaces within the community
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user