I am trying to make an infinite loop in my listview, when index is at the end and user continue to scroll to left the next item will be the first one
ListView.builder(
controller: _controller,
scrollDirection: Axis.horizontal,
itemCount: packs.length,
itemBuilder: (context, index) {
_index = index;
print(index);
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
],
);
},
),
I want user can infinite swipe, how can I do ?
ListView.builder(
physics: BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
// itemCount: items.length,
itemBuilder: (context, index) {
final i = index % items.length;//<----to the right
final item = items[i];
return ItemSwiper(
item: item,
onTab: () => _.goToDetailItem(item: item),
);
})
you can remove itemCount and try... But you cannot use a particular index, just showing a widget on that position. And you can print Index but make sure that you don't use an index with any external data source having limited data.
ListView.builder(
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text('Item ${index + 1}'),
);
},
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With