简体   繁体   English

RangeError(索引):无效值:不在0..5范围内(包括6):Flutter SliverChildBuilderDelegate

[英]RangeError (index): Invalid value: Not in range 0..5, inclusive: 6 : Flutter SliverChildBuilderDelegate

I was using using firestore with flutter SliverChildBuilderDelegate. 我用的是用firestoreflutter SliverChildBuilderDelegate. SliverChildBuilderDelegate building a infinite index. SliverChildBuilderDelegate构建无限索引。 but my firestore has only 6 documents. 但是我的firestore只有6个文件。 resulting 造成

an error of RangeError (index): Invalid value: Not in range 0..5, inclusive: 7 RangeError(索引)错误:无效值:不在0..5范围内,包括7

how can I solve this? 我该如何解决?

There is a childCount property in SliverChildBuilderDelegate but not working also tried the offset. SliverChildBuilderDelegate中有一个childCount属性,但不起作用,也尝试了偏移量。

new SliverFixedExtentList(
       itemExtent: 80.0,

delegate: new SliverChildBuilderDelegate(

(context, index ,{childCount:5}) => StreamBuilder<QuerySnapshot>(

stream: Firestore.instance.collection('books').orderBy('open_date')
.snapshots(),

builder: (context, snapshot) {

                        print("\n\n\n\n "+snapshot.data.documents.length.toString());
                        print("\n\n\n\n\n\n");
                      if (!snapshot.hasData) return CircularProgressIndicator();
                      else if(index<snapshot.data.documents.length){
                      return Card(
                        child: ListTile(

                          leading: child1,
                          title: Text(snapshot.data.documents[index]['title']),
                          subtitle:
                              Text(snapshot.data.documents[index]['result']),
                        ),
                      );
                      }else{
                      return Text("data");}
                    },
                  ),
            ),
          ),

Sorry for pasting a wrong formatted code. 抱歉,您粘贴的格式错误的代码。 I tried a lot but may be stack doesn't support flutter dart 我尝试了很多,但可能是堆栈不支持飞镖

Try removing the childCount from the SliverChildBuilderDelegate arguments. 尝试从SliverChildBuilderDelegate参数中删除childCount。 Instead, place childCount directly after your code block for builder. 而是将childCount直接放在构建器的代码块之后。 (here is an example to look at: https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/pesto_demo.dart ) (这里是一个例子: https : //github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/pesto_demo.dart

    new SliverFixedExtentList(
       itemExtent: 80.0,

    delegate: new SliverChildBuilderDelegate(

    (context, index) => StreamBuilder<QuerySnapshot>(

    stream: Firestore.instance.collection('books').orderBy('open_date')
    .snapshots(),

    builder: (context, snapshot) {

                        print("\n\n\n\n "+snapshot.data.documents.length.toString());
                        print("\n\n\n\n\n\n");
                      if (!snapshot.hasData) return CircularProgressIndicator();
                      else if(index<snapshot.data.documents.length){
                      return Card(
                        child: ListTile(

                          leading: child1,
                          title: Text(snapshot.data.documents[index]['title']),
                          subtitle:
                              Text(snapshot.data.documents[index]['result']),
                        ),
                      );
                      }else{
                      return Text("data");}
                    },
                     childCount:5,
                  ),
            ),
          ),

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RangeError(索引):无效值:不在包含范围内 0..5:-5 - RangeError (index): Invalid value: Not in inclusive range 0..5: -5 Flutter:RangeError(索引):无效值:不在包含范围 0..27:28 - Flutter : RangeError (index): Invalid value: Not in inclusive range 0..27: 28 Flutter 错误:RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 - Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 RangeError (index): Invalid value: Not in range 0..3, inclusive: 4 in Flutter - RangeError (index): Invalid value: Not in range 0..3, inclusive: 4 in Flutter 颤振范围错误(索引):无效值:不在包含范围内 0..4:CarouselSlider 上的 5 - flutter RangeError (index): Invalid value: Not in inclusive range 0..4: 5 on CarouselSlider RangeError (index): Invalid value: Not in inclusive range 0..13: 14 Flutter - RangeError (index): Invalid value: Not in inclusive range 0..13: 14 Flutter RangeError(索引):无效值:不在 0..2 范围内,包括:3 - RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 RangeError(索引):无效值:不在包含范围内 0..1:收藏某个项目时为 2 - RangeError (index): Invalid value: Not in inclusive range 0..1: 2 when favoriting an item Flutter:RangeError(索引):无效值:有效值范围为空:0 - Flutter: RangeError (index): Invalid value: Valid value range is empty: 0 Flutter 范围错误:无效值:....,包含:-1 - Flutter Range Error : Invalid value: ...., Inclusive: -1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM