1

我正在计划一个使用 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 是否也会监听“消息”集合中的变化?

4

1 回答 1

3

不,只要没有安装屏幕,它就不会听。

于 2020-07-04T14:48:03.567 回答