[英]RangeError (index): Invalid value: Not in range 0..5, inclusive: 6 : Flutter SliverChildBuilderDelegate
I was using using firestore
with flutter SliverChildBuilderDelegate.
我用的是用firestore
有flutter 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.