Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3

后端 未结 5 1801
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 00:49

I am using a long list in flutter. All the items are rendering fine but also following error :

RangeError (index): Invalid value: Not in range 0..2, inclusive: 3         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-05 01:28

    You should pass the itemCount parameter to the ListView.builder to allow it to know the item count

    Widget getList() {
      List list = getListItems();
      ListView myList = new ListView.builder(
        itemCount: list.length,
        itemBuilder: (context, index) {
        return new ListTile(
          title: new Text(list[index]),
        );
      });
      return myList;
    }
    

提交回复
热议问题