vedartm / paginate_firestore

A flutter package to simplify pagination with firestore data 🗃
https://pub.dev/packages/paginate_firestore
MIT License
113 stars 138 forks source link

Feature Request #73

Closed waletoyo1 closed 3 years ago

waletoyo1 commented 3 years ago

Hi, your package is very useful and awesome. I'm wondering if you could add ability to add a widget in between the listviews after certain number of items. Thanks.

vedartm commented 3 years ago

At this moment you can manually do it by manipulating the itemBuilder like this.

      itemBuilder: (_, index, list) => index == 3
          ? const Padding(
              padding: EdgeInsets.symmetric(horizontal: EBDimens.padding),
              child: ReferCard(),
            )
          : FeedCard(feed: list[index > 3 ? index - 1 : index]),
waletoyo1 commented 3 years ago

Thanks, but am not very clear with the answer. Let me explain my issue further: For example, I have an app that displays list of posts in a list (firestore), I want to display a widget e.g a banner after 5 posts. This banner will continue to be displayed continuously after 5 posts have passed. Thanks.

vedartm commented 3 years ago

Can you elaborate on what do you mean by continue to be displayed?

a. Is the banner persistent even if we scroll to the 6th or 7th post? (or) b. Is the banner gonna exist in the list as the 6th position in the list and the rest of the posts start from the 7th position?

waletoyo1 commented 3 years ago

Thanks for your response. a. The banner will be placed in a list. The number of banner item in the list determines if the banner will be persistent or dynamic. b. The banner will be at the 6th, 11th, 16th position and so on. If the number of banner items in the list is just one, the banner will be at position 6, 11, 16, and so on. If the banner item is more than one, each item will take the available 5th or nth position after the post items in the listview.

vedartm commented 3 years ago

Understood @waletoyo1. Try this if you wanna repeat in 5th, 10th, 15th, and so on.

      itemBuilder: (_, index, list) => index % 5 == 4
          ? BannerWidget()
          : PostWidget(post: list[index - (index / 5).floor()]),
waletoyo1 commented 3 years ago

Thank you very much. It worked exactly the way I wanted it, but I did not add list[index - (index/5).floor() to the post widget. Is there any implication if this isn't added? Also regarding the dynamic banner widget, I did it this way:

var list = ['a', 'b', 'c', 'd', 'e']; var randList = list[Random().nextInt(list.length)]; //called inside the itembuilder function then I displayed the items like this: index % 5 == 4 ? Text(randList) :Postwiidget()

waletoyo1 commented 3 years ago

I also got this online:

https://flutter.dev/docs/cookbook/lists/mixed-list

waletoyo1 commented 3 years ago

I also got this online:

https://flutter.dev/docs/cookbook/lists/mixed-list

waletoyo1 commented 3 years ago

But I noticed some items in the listview are replaced with the banner widget. How can we ensure all items get displayed?

vedartm commented 3 years ago

But I noticed some items in the listview are replaced with the banner widget. How can we ensure all items get displayed?

That's why I added list[index - (index/5).floor(). Try adding and check if you get all the items.

waletoyo1 commented 3 years ago

I got errors when I did it this way : documentSnapshot.data()?['post'][index - (index/5).floor()].

vedartm commented 3 years ago

It will be solved if you optimize the number used in the index accordingly.

waletoyo1 commented 3 years ago

Ok, thanks.

jslattery26 commented 3 years ago

Understood @waletoyo1. Try this if you wanna repeat in 5th, 10th, 15th, and so on.

      itemBuilder: (_, index, list) => index % 5 == 4
          ? BannerWidget()
          : PostWidget(post: list[index - (index / 5).floor()]),

How are you getting 'list' as a parameter instead of documentSnapshot ?

vedartm commented 3 years ago

Sorry @jslattery26 my bad. I am maintaining two packages and got confused with that. This package does not have index yet.