Reputation: 419
I was using using firestore
with flutter SliverChildBuilderDelegate.
SliverChildBuilderDelegate
building a infinite index. but my firestore
has only 6 documents.
resulting
an error of RangeError (index): Invalid value: Not in range 0..5, inclusive: 7
how can I solve this?
There is a childCount property in SliverChildBuilderDelegate but not working also tried the offset.
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
Upvotes: 0
Views: 1565
Reputation: 287
Try removing the childCount from the SliverChildBuilderDelegate arguments. Instead, place childCount directly after your code block for builder. (here is an example to look at: 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,
),
),
),
Upvotes: 1