firebase - 如何使用流生成器检查 Firebase 文档的长度
问题描述
在我的颤振 firebase 应用程序中,我可以使用查询快照获取用户在 firebase 中的活动文档的长度。但是,我希望在用户无需刷新页面的情况下实时更新文档数量。我可以通过使用流生成器转换下面的代码来获得实时长度来做到这一点吗?我该怎么做?这是我现在使用的代码,它运行良好,但不会实时更新。
//this is the code I want to convert to stream
//builder.
static Future<int> numActivities(String userId)
async {
QuerySnapshot userActivitiesSnapshot = await
activitiesRef
.document(userId)
.collection('userActivities')
.where('seen', isEqualTo: '')
.getDocuments();
return userActivitiesSnapshot.documents.length;
}
解决方案
您需要使用“返回包含类docs
”的属性,如下所示:List
DocumentSnapshot
return userActivitiesSnapshot.docs.length;
推荐阅读
- kdb - 如何知道从触发.z.pc函数的aq服务断开连接的客户端的句柄,kdb+
- python - 如果 Python 的模式中存在,则从 db2 表中删除值
- javascript - 从最后一行谷歌应用程序脚本增加 ID
- excel - 在未锁定范围内动态锁定单元格
- python - 如何使用 Python 检查存储为 URL 的图像的图像透明度?
- java - 使用 jooq 从选择中排除提供的值
- elasticsearch - 启动 Elassandra - Cassandra 与 Elasticsearch 失败并没有配置 path.home
- php - PHP MYSQL:在当前搜索代码中加入关键字表
- java - 在 cmd 中运行基于 gradle 的 Java 应用程序时出现 ClassNotFoundException
- javascript - 使用 JavaScript 遍历表单以获取选定的多选、下拉和复选框项目