Can I add a CircularProgressIndicator()
to the end of the GridView every time the bool isLoadingPosts
is true?
Widget imagePostsWidget = imagePosts != null
? GridView.builder(
physics: BouncingScrollPhysics(),
controller: ProfileScreen.scrollController,
padding: EdgeInsets.only(top: 3),
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemCount: imagePosts.length,
itemBuilder: (BuildContext context, int index) => PostCard(
imagePost: imagePosts[index],
imageUrl: imagePosts[index].imageUrl,
),
)
: SizedBox();
This is my code currently for fetching the posts with infinite scroll. The only thing I need is an CircularProgressIndicator()
added to the end of the GridView, but I just cant figure out a way to achieve that.
I want to have something like this:
Widget imagePostsWidget = imagePosts != null
? GridView.builder(
physics: BouncingScrollPhysics(),
controller: ProfileScreen.scrollController,
padding: EdgeInsets.only(top: 3),
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemCount: imagePosts.length,
itemBuilder: (BuildContext context, int index) => PostCard(
imagePost: imagePosts[index],
imageUrl: imagePosts[index].imageUrl,
),
if(isLoadingPosts) {
return CirularProgressIndicator();
}
)
: SizedBox();
2
Answers
Yes,
you can achieve, Please check the below is code. Please try that code and inform me, is it works for you?
In the above code, We have used the
ScrollController
That Listens for when the user reaches at the end of the list. When the user reaches at the end of the list, we set theisLoadingPosts
flag to true and load more. we show theCircularProgressIndicator
at the end of the list/post. we set theisLoadingPosts
false to update the widget tree to show the new postYou can try this approach: