我正在计划一个使用 Cloud Firestore 作为后端的新 Flutter 应用程序。为了确保成本不会爆炸式增长,我想确定我的听众什么时候收听变化。
例如,当我使用以下代码通过集合进行查询时
Stream<List<Message>> getMessages(String userUid) {
return _users // A Firestore Collection
.document(userUid)
.collection('messages')
.limit(20)
.snapshots()
.map((snap) {
return snap.documents
.map((doc) => Message(doc.data['author'], doc.data['message']))
.toList();
});
}
并将其StreamProvider
用作屏幕/脚手架的父级。当我在另一个屏幕上时,Flutter 是否也会监听“消息”集合中的变化?