flutter - 扑。创建列表firestore 文档和集合
问题描述
我正在尝试从 Firestore 获取文档列表(documentID)并将其添加到列表中。我已经看到了一些选择,但由于我在这个领域有点新,也许显而易见的事情对我来说变得困难了。而且我不知道这些行应该在代码中的确切位置,例如在 initState 中。
这是我选择的选项之一,但它只生成实例而不是文档的名称。
final QuerySnapshot result =
await Firestore.instance.collection('submits').getDocuments();
final List<DocumentSnapshot> documents = result.documents;
List<String> myListString = []; // My list I want to create.
myListString.add(documents); // The way I try to add the doc list to my String list.
以数据库为例。我想将文档 ID 列表获取到 List-String-
如果可能的话,你可以告诉我是否有类似的方法来应用它来获得一个 List 但在两个或多个集合的情况下。
解决方案
看起来您想要的是文档ID列表,对吗?
如果是这样,这应该工作:
final QuerySnapshot result =
await Firestore.instance.collection('submits').getDocuments();
final List<DocumentSnapshot> documents = result.documents;
List<String> myListString = []; // My list I want to create.
documents.forEach((snapshot) {
myListString.add(snapshot.documentID)
});
推荐阅读
- ios - 我创建了新的 React-Native 项目,但它没有在我的 iOS 模拟器上运行并出现此错误
- segmentation-fault - 我无法在此代码中找出任何错误,但它显示 seg 错误,有人可以帮助我吗?
- fortran - 尽管 OpenMP 中的每一步都有障碍,但可能的竞争条件
- python - 自定义对象检测 OpenCV 代码错误
- javascript - 响应未在控制台上打印
- azure - 新 sprint 在容量选项卡中显示旧成员
- python - matplotlib 中 barplot 中的 fill_between()
- python - Django Query group_by datetime 包含重复的日期数据
- node.js - 使用 AWS IoT 将 100MB 以上的文件从 AWS 云流式传输到事物
- php - 使用过滤器修改已注册的自定义帖子类型的参数