Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How can I load more pages dynamically? #43

Open
khayargoli opened this issue Mar 14, 2023 · 1 comment
Open

How can I load more pages dynamically? #43

khayargoli opened this issue Mar 14, 2023 · 1 comment

Comments

@khayargoli
Copy link

My page view is working perfectly and thanks to this awesome plugin..

I wanted to implement pagination next and want to load more pages when user scrolls to the end of preloaded pages. (currently 10 pages at a time)

How can I achieve this? Any hints would be greatly appreciated.

Thanks

@edwinmrb
Copy link

edwinmrb commented Jun 13, 2023

@khayargoli
listen to the onPageChanged: (index), here we have the current index, compare with the total number of elements you have in your list, if you have less than 5 left you can bring more.

`PreloadPageView.builder(
controller: controllerPageView,
itemCount: state.isLoadingMore ? posts.length + 1 : posts.length,
onPageChanged: (index) {
getMoreItems(index, posts.length);
},
scrollDirection: Axis.vertical,
preloadPagesCount: 3,
itemBuilder: (_, index) {
if (state.isFailureMore && index == posts.length) {
return AppTextFailure(
title: mapFailuresToText(s, state.failure!),
fullScreen: false,
);
}
if (state.isLoadingMore && index == posts.length) {
return const HomeCardVideoFullPlayerLoading();
}
return HomeCardVideoFullPlayer(post: posts[index]);
},
physics: const AlwaysScrollableScrollPhysics(),
);

void getMoreItems(int index, int length) {
final isBottom = index > length - 5;
if (isBottom && !postCubit.state.hasReachedMax && !postCubit.state.isLoading) {
getAllPost();
}
}
`
Here a detail you have to block until they arrive, the new items, and while you can show a loading paginate, in the end if it hasn't arrived yet, so you will have an infinite pagination.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants