Debug School

rakesh kumar
rakesh kumar

Posted on

How to show items from specific index in a listview builder flutter

how-to-show-items-from-specific-index-in-a-listview-builder-flutter
how-to-use-conditional-statement-within-child-attribute-of-a-flutter-widget-cen

I want to start showing the list items from index 5

ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
  return ListTile(
    title: Text('${items[index]}'),
  );
},
);
Enter fullscreen mode Exit fullscreen mode

Check this out

ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
  if(index < 5) return SizedBox();
  return ListTile(
    title: Text('${items[index]}'),
  );
},
);
Enter fullscreen mode Exit fullscreen mode

===========OR===========

I am not sure if this is what you are looking for, but you can give it a try. To only show specific items based on certain conditions, you can use the "Visibility" widget as the example shown below.

 ListView.builder(
      itemCount: items.length,
      itemBuilder: (context, index) {
        return Visibility(
          visible: index>5,
          child: ListTile(
            title: Text('${items[index]}'),
          ),
        );
      },
    );
Enter fullscreen mode Exit fullscreen mode

Maybe this is what you are looking for

ListView.builder(
itemCount: items.length - 5,
itemBuilder: (context, index) {
  return ListTile(
    title: Text(items[index+5].toString()),
  );
},
);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)