Home > database >  how can i make items repeat again if i arrive the end of list
how can i make items repeat again if i arrive the end of list

Time:12-30

i have the following

  ListView.builder(
   controller: controller,
   itemCount: 50, 
   itemBuilder: (BuildContext context, int index) { 
   return Text('hello world');
   },
    )

now when i scroll to last index it stop scroll anymore .. but how can i force it to keep scroll with same items that i passed through like following

1
2
3
4
etc .. 50

keep scroll 
1
2
3
4
etc .. 50

and so

what i am doing now is adding others same 50 items but it not good idea

how could i make it auto repeat without End . without to add

CodePudding user response:

Simply leave out the itemCount and in the itemBuilder you could modulo 50 the index to have them repeat every 50. For example:

ListView.builder(
  controller: controller,
  itemBuilder: (BuildContext context, int index) {
    index = index % 50;
    return Text('hello world $index');
  },
)
  • Related