[英]Flutter does popping a screen with a firestore stream reread the document
我是 flutter 和 firebase 上的新手,我目前正在开发一个应用程序,它有一个来自 firestore 快照的带有 stream 的流生成器,statefulwidget class 或多或少是这样的:
StreamBuilder(
stream: ItemService().getItemsWithStatus([1]),
builder: (context, AsyncSnapshot<List<Item>> snapshot) {
//Widget to show information
}
)
我像这样从 itemService class 得到 stream
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());
}
}
问题是,当我用那个 streambuilder 关闭屏幕然后重新打开它时,它会再次从 firestore 读取数据(并将我的读取计数加倍)吗? 如果是,那么我该怎么做才能避免重读?
谢谢,任何建议将不胜感激
可能没有。 您可以检查此更改:
(DocumentSnapshot document) {
print(document.metadata.isFromCache);
Item.fromDb(document.data());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.