I am fairly new on flutter and firebase, i am currently developing app which have a streambuilder with stream from a firestore snapshot, the statefulwidget class is more or less like this:
StreamBuilder(
stream: ItemService().getItemsWithStatus([1]),
builder: (context, AsyncSnapshot<List<Item>> snapshot) {
//Widget to show information
}
)
and i get the stream from itemService class like this
class ItemService{
Stream<List<Item>> getItemsWithStatus(List<int> status) {
return _firestore
.collection(itemsPath)
.where('status', whereIn: status)
.snapshots()
.map((QuerySnapshot snapshot) => snapshot.docs
.map((DocumentSnapshot document) => Item.fromDb(document.data()))
.toList());
}
}
the question is, when i close the screen with that streambuilder and then reopen it would it read the data again from firestore (and doubling my read count)? if yes then how can i possibly do to avoid reread?
Thankyou, any advice will really be appreciated
Probably no. You can check with this alteration:
(DocumentSnapshot document) {
print(document.metadata.isFromCache);
Item.fromDb(document.data());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.