ulukbek
ulukbek

Reputation: 493

Flutter. How to stop at index x ListView.builder to draw remaining items. Assume, n is size of the list and x is smaller than n

How to stop at index x ListView.builder to draw remaining items. Assume, n is size of the list and x is smaller than n.

lets n is 10 and x is any number until 10. Assume x is 8, then I want to show items from index 0 until 8. So I have to tell somehow to ListView to stop drawing remaining data.

I am using ListView inside ListView. And I want my 2nd ListView to behave the way I explained above. Is there anyone have done this before?

Upvotes: 0

Views: 316

Answers (1)

Kaushik Chandru
Kaushik Chandru

Reputation: 17772

A list view will have item count, if you add item count as 1 it will only add one item to the widget tree even if the list supplied to it has higher than the count that you mentioned.

ListView.builder(
  itemCount: 5, //<--count that you wish to stop at.
  itemBuilder(context, index){
    return Container(
      child: Text("${_someList[index]}"),
    );
  }
)

Upvotes: 1

Related Questions