mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
refactor: improve readability and structure in SidebarWidget's space tile handling
This commit is contained in:
@ -113,8 +113,8 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
Text(
|
Text(
|
||||||
'Communities',
|
'Communities',
|
||||||
style: context.textTheme.titleMedium?.copyWith(
|
style: context.textTheme.titleMedium?.copyWith(
|
||||||
color: ColorsManager.blackColor,
|
color: ColorsManager.blackColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () => _navigateToBlank(context),
|
onTap: () => _navigateToBlank(context),
|
||||||
@ -183,23 +183,30 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
onExpansionChanged: (title, expanded) {},
|
onExpansionChanged: (title, expanded) {},
|
||||||
children: hasChildren
|
children: hasChildren
|
||||||
? community.spaces
|
? community.spaces
|
||||||
.where((space) => (space.status != SpaceStatus.deleted ||
|
.where((space) {
|
||||||
space.status != SpaceStatus.parentDeleted))
|
final isDeleted = space.status != SpaceStatus.deleted;
|
||||||
.map((space) => _buildSpaceTile(space, community))
|
final isParentDeleted = space.status != SpaceStatus.parentDeleted;
|
||||||
|
return (isDeleted || isParentDeleted);
|
||||||
|
})
|
||||||
|
.map((space) => _buildSpaceTile(space: space, community: community))
|
||||||
.toList()
|
.toList()
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildSpaceTile(SpaceModel space, CommunityModel community,
|
Widget _buildSpaceTile({
|
||||||
{int depth = 1}) {
|
required SpaceModel space,
|
||||||
|
required CommunityModel community,
|
||||||
|
int depth = 1,
|
||||||
|
}) {
|
||||||
bool spaceIsExpanded = _isSpaceOrChildSelected(space);
|
bool spaceIsExpanded = _isSpaceOrChildSelected(space);
|
||||||
|
final isSelected = _selectedId == space.uuid;
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.only(left: depth * 16.0),
|
padding: EdgeInsets.only(left: depth * 16.0),
|
||||||
child: SpaceTile(
|
child: SpaceTile(
|
||||||
title: space.name,
|
title: space.name,
|
||||||
key: ValueKey(space.uuid),
|
key: ValueKey(space.uuid),
|
||||||
isSelected: _selectedId == space.uuid,
|
isSelected: isSelected,
|
||||||
initiallyExpanded: spaceIsExpanded,
|
initiallyExpanded: spaceIsExpanded,
|
||||||
onExpansionChanged: (expanded) {},
|
onExpansionChanged: (expanded) {},
|
||||||
onItemSelected: () {
|
onItemSelected: () {
|
||||||
@ -212,11 +219,14 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
SelectSpaceEvent(selectedCommunity: community, selectedSpace: space),
|
SelectSpaceEvent(selectedCommunity: community, selectedSpace: space),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
children: space.children.isNotEmpty
|
children: space.children
|
||||||
? space.children
|
.map(
|
||||||
.map((childSpace) => _buildSpaceTile(childSpace, community))
|
(childSpace) => _buildSpaceTile(
|
||||||
.toList()
|
space: childSpace,
|
||||||
: [],
|
community: community,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user