один и тот же индекс несколько раз в ListView.builder

Я хочу показать 2 пользовательских виджета и список (данные api). Я не могу использовать _1 _. (Потому что хочу пролистать один раз)

Здесь отсутствуют данные 0 и 1, поступающие из 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(
              ...
            ));
      }),

person BloodLoss    schedule 24.10.2019    source источник


Ответы (1)


Просто настройте счетчик и индекс.

  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(
              ... 
            ));
      }),
person Richard Heap    schedule 24.10.2019