BIS Tech
BIS Tech

Reputation: 19514

same index multiple times on ListView.builder

I want to show 2 custom widgets and listview(api data). I can't use column.(Because I want to scroll one time)

In here, missing 0 and 1 data coming from api

  ListView.builder(
      itemCount: get.length,//3
      itemBuilder: (BuildContext context, int index) {
        if(index == 0){
         return Text('Generate By Developer');
        }
        if(index == 1){
         return Text('Generate By Developer');
        }
        return Bubble(
            style: styleSomebody,
            child: Container(
              ...
            ));
      }),

Upvotes: 0

Views: 1592

Answers (1)

Richard Heap
Richard Heap

Reputation: 51769

Just tweak the count and the index.

  ListView.builder(
      itemCount: get.length + 2, // add room for the two extra
      itemBuilder: (BuildContext context, int index) {
        if(index == 0){
         return Text('Generate By Developer');
        }
        if(index == 1){
         return Text('Generate By Developer');
        }
        index -= 2; // decrement index so that it's now in the range [0..length]
        return Bubble(
            style: styleSomebody,
            child: Container(
              ... 
            ));
      }),

Upvotes: 1

Related Questions