Closed waletoyo1 closed 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]),
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.
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?
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.
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()]),
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()
I also got this online:
I also got this online:
But I noticed some items in the listview are replaced with the banner widget. How can we ensure all items get displayed?
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.
I got errors when I did it this way : documentSnapshot.data()?['post'][index - (index/5).floor()].
It will be solved if you optimize the number used in the index accordingly.
Ok, thanks.
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 ?
Sorry @jslattery26 my bad. I am maintaining two packages and got confused with that. This package does not have index yet.
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.