【发布时间】:2021-04-20 21:22:29
【问题描述】:
我对flutter和firebase相当陌生,我目前正在开发一个应用程序,它有一个带有来自firestore快照的流的streambuilder,statefulwidget类或多或少是这样的:
StreamBuilder(
stream: ItemService().getItemsWithStatus([1]),
builder: (context, AsyncSnapshot<List<Item>> snapshot) {
//Widget to show information
}
)
我像这样从 itemService 类中获取流
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());
}
}
问题是,当我使用该流构建器关闭屏幕然后重新打开它时,它会再次从 Firestore 读取数据(并使我的读取计数加倍)吗?如果是,那我怎么可能避免重读?
谢谢,任何建议都将不胜感激
【问题讨论】:
标签: firebase flutter google-cloud-firestore