【问题标题】:Flutter: When is a listener to a Firestore Document / Query activatedFlutter:何时激活 Firestore 文档/查询的侦听器
【发布时间】:2020-10-24 22:01:27
【问题描述】:

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

【问题讨论】:

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

标签: firebase flutter google-cloud-firestore dart-stream


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-06-06
    • 2023-03-19
    • 2020-01-07
    • 1970-01-01
    • 2018-09-04
    • 2021-06-07
    • 2021-08-07
    • 1970-01-01
    • 2013-01-19
    相关资源
    最近更新 更多