shows a loading indicator when loading.

This commit is contained in:
Faris Armoush
2025-06-22 12:46:17 +03:00
parent 8494f0a8f1
commit b79ab06d95
4 changed files with 39 additions and 22 deletions

View File

@ -42,11 +42,9 @@ class _SpaceManagementCommunitiesTreeState
}
void _onSearchChanged(String searchQuery) {
context.read<CommunitiesBloc>().add(
LoadCommunities(LoadCommunitiesParam(
search: searchQuery.trim(),
)),
);
context
.read<CommunitiesBloc>()
.add(LoadCommunities(LoadCommunitiesParam(search: searchQuery.trim())));
}
void _onLoadMore() {
@ -80,6 +78,13 @@ class _SpaceManagementCommunitiesTreeState
CommunitiesStatus.success => _buildCommunitiesTree(context, state),
CommunitiesStatus.failure => _buildErrorState(context, state),
},
Visibility(
visible: state.isLoadingMore,
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Center(child: CircularProgressIndicator()),
),
),
],
),
);
@ -132,14 +137,24 @@ class _SpaceManagementCommunitiesTreeState
}
return Expanded(
child: SpaceManagementSidebarCommunitiesList(
communities: state.communities,
onLoadMore: state.hasNext ? _onLoadMore : null,
isLoadingMore: state.isLoadingMore,
hasNext: state.hasNext,
itemBuilder: (context, index) {
return _buildCommunityTile(context, state.communities[index]);
},
child: Stack(
children: [
SpaceManagementSidebarCommunitiesList(
communities: state.communities,
onLoadMore: state.hasNext ? _onLoadMore : null,
isLoadingMore: state.isLoadingMore,
hasNext: state.hasNext,
itemBuilder: (context, index) {
return _buildCommunityTile(context, state.communities[index]);
},
),
if (state.status == CommunitiesStatus.loading &&
state.communities.isNotEmpty)
ColoredBox(
color: Colors.white.withValues(alpha: 0.7),
child: const Center(child: CircularProgressIndicator()),
),
],
),
);
}

View File

@ -37,7 +37,6 @@ class _SpaceManagementSidebarCommunitiesListState
void _onScroll() {
if (_scrollController.position.pixels >=
_scrollController.position.maxScrollExtent - 100) {
// Trigger pagination when user is close to the bottom
if (widget.hasNext && !widget.isLoadingMore && widget.onLoadMore != null) {
widget.onLoadMore!();
}
@ -67,7 +66,6 @@ class _SpaceManagementSidebarCommunitiesListState
@override
Widget build(BuildContext context) {
// Calculate item count including loading indicator
final itemCount = widget.communities.length + (widget.isLoadingMore ? 1 : 0);
return SingleChildScrollView(