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

后端 未结 5 1798
被撕碎了的回忆
被撕碎了的回忆 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:21
    Widget getListView(){
      var itemList = getListElement();
       var list = ListView.builder(
         itemCount: itemList.length,
           itemBuilder:(context, index){
             return ListTile(
               title: Text(itemList[index]),   
             );
             }
       );
       return list;
    }
    
    0 讨论(0)
  • 2021-02-05 01:23

    it works in small scale but in my case it doesn't work.

    [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: RangeError (index): Invalid value: Not in inclusive range 0..17: 18
    
    0 讨论(0)
  • 2021-02-05 01:27

    if you are using StreamBuilder then you must use this line of code

      StreamBuilder(
                      stream: FirebaseFirestore.instance.collection("Tooth")
                      .orderBy("date", descending: false).snapshots() ,
                    
                      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
                     
                        if(snapshot.hasData)
                        {
                          return ListView.builder(
                            itemCount: snapshot.data.docs.length,
                              padding: const EdgeInsets.only( top: 20.0),
                            itemBuilder: (BuildContext context, int index) {
                               DocumentSnapshot ds = snapshot.data.docs[index];
     },
                          );
                        }
                       
                      },
                    ),
    
    0 讨论(0)
  • 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<String> list = getListItems();
      ListView myList = new ListView.builder(
        itemCount: list.length,
        itemBuilder: (context, index) {
        return new ListTile(
          title: new Text(list[index]),
        );
      });
      return myList;
    }
    
    0 讨论(0)
  • 2021-02-05 01:29

    I had this problem inside a GridView, but it had nothing to do with my GridView. I was splitting addresses by commas, ex addresses[index].split(',')[0], but I came across a address that had no commas which is why I suddenly got this error. Look closely through the debug console to find the exact line of the error, and test every piece of code in your GridView to pinpoint the error.

    0 讨论(0)
提交回复
热议问题