selected space/community become dark

This commit is contained in:
hannathkadher
2024-11-19 18:52:26 +04:00
parent 8a2efb2694
commit c3a5b0b351
3 changed files with 26 additions and 22 deletions

View File

@ -84,9 +84,7 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
}); });
}, },
child: Icon( child: Icon(
_isExpanded _isExpanded ? Icons.keyboard_arrow_down : Icons.keyboard_arrow_right,
? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_right,
color: Colors.grey, color: Colors.grey,
size: 16.0, // Adjusted size for better alignment size: 16.0, // Adjusted size for better alignment
), ),
@ -95,7 +93,6 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
Expanded( Expanded(
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
// Triggerxq the onItemSelected callback when the name is tapped
if (widget.onItemSelected != null) { if (widget.onItemSelected != null) {
widget.onItemSelected!(); widget.onItemSelected!();
} }
@ -106,8 +103,7 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
style: TextStyle( style: TextStyle(
color: widget.isSelected color: widget.isSelected
? Colors.black // Change color to black when selected ? Colors.black // Change color to black when selected
: ColorsManager : ColorsManager.lightGrayColor, // Gray when not selected
.lightGrayColor, // Gray when not selected
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
), ),
@ -116,9 +112,7 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
], ],
), ),
// The expanded section (children) that shows when the tile is expanded // The expanded section (children) that shows when the tile is expanded
if (_isExpanded && if (_isExpanded && widget.children != null && widget.children!.isNotEmpty)
widget.children != null &&
widget.children!.isNotEmpty)
Padding( Padding(
padding: const EdgeInsets.only(left: 48.0), // Indented children padding: const EdgeInsets.only(left: 48.0), // Indented children
child: Column( child: Column(

View File

@ -29,6 +29,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
String _searchQuery = ''; // Track search query String _searchQuery = ''; // Track search query
String? _selectedCommunityUuid; String? _selectedCommunityUuid;
String? _selectedSpaceUuid; String? _selectedSpaceUuid;
String? _selectedId;
@override @override
void initState() { void initState() {
@ -173,15 +174,19 @@ class _SidebarWidgetState extends State<SidebarWidget> {
Widget _buildCommunityTile(CommunityModel community) { Widget _buildCommunityTile(CommunityModel community) {
bool hasChildren = community.spaces.isNotEmpty; bool hasChildren = community.spaces.isNotEmpty;
bool isSelectedCommunity = bool isSelectedCommunity = _selectedCommunityUuid == community.uuid;
_selectedCommunityUuid == community.uuid; // Check if this community is selected
// Check if this community is selected
return CommunityTile( return CommunityTile(
title: community.name, title: community.name,
isSelected: isSelectedCommunity, key: ValueKey(community.uuid),
isSelected: _selectedId == community.uuid,
isExpanded: false, isExpanded: false,
onItemSelected: () { onItemSelected: () {
setState(() { setState(() {
_selectedSpaceUuid = community.uuid; // Update the selected community _selectedId = community.uuid;
_selectedCommunityUuid = community.uuid;
_selectedSpaceUuid = null; // Update the selected community
}); });
if (widget.onCommunitySelected != null) { if (widget.onCommunitySelected != null) {
@ -198,21 +203,26 @@ class _SidebarWidgetState extends State<SidebarWidget> {
} }
Widget _buildSpaceTile(SpaceModel space, CommunityModel community) { Widget _buildSpaceTile(SpaceModel space, CommunityModel community) {
bool isSelectedSpace = _isSpaceOrChildSelected(space); // Check if space should be expanded bool isExpandedSpace = _isSpaceOrChildSelected(space);
bool isSelectedSpace = _selectedSpaceUuid == space.uuid;
// Check if space should be expanded
return SpaceTile( return SpaceTile(
title: space.name, title: space.name,
isSelected: isSelectedSpace, key: ValueKey(space.uuid),
initiallyExpanded: isSelectedSpace, isSelected: _selectedId == space.uuid,
initiallyExpanded: isExpandedSpace,
onExpansionChanged: (bool expanded) { onExpansionChanged: (bool expanded) {
_handleExpansionChange(space.uuid ?? '', expanded); _handleExpansionChange(space.uuid ?? '', expanded);
}, },
onItemSelected: () { onItemSelected: () {
if (widget.onCommunitySelected != null || widget.onSpaceSelected != null) { setState(() {
widget.onCommunitySelected!(community); // Pass the entire community _selectedId = space.uuid;
} _selectedSpaceUuid = space.uuid;
_selectedCommunityUuid = community.uuid; // Update selected community
});
print(_selectedSpaceUuid);
if (widget.onSpaceSelected != null) { if (widget.onSpaceSelected != null) {
widget.onSpaceSelected!(space); // Pass the entire community widget.onSpaceSelected!(space);
} }
}, },
children: space.children.isNotEmpty children: space.children.isNotEmpty

View File

@ -36,7 +36,7 @@ class _SpaceTileState extends State<SpaceTile> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CustomExpansionTile( return CustomExpansionTile(
isSelected: false, isSelected: widget.isSelected,
title: widget.title, title: widget.title,
initiallyExpanded: _isExpanded, initiallyExpanded: _isExpanded,
onItemSelected: widget.onItemSelected, onItemSelected: widget.onItemSelected,