firebase - 如何从Firestore子集合中获取数据

标签 firebase flutter dart google-cloud-firestore

我有一个Firestore数据库,其中有“歌手”,然后在每个歌手中都有每个歌手的“歌曲列表”子集合。我能够从主集合中获取数据,但不能从子集合中获取数据。你们可以帮忙吗?
流生成器

StreamBuilder(
        stream: Firestore.instance.collection('singers').snapshots(),
ListView.Builder
ListView.builder(
                itemCount: snapshot.data.documents.length,
                itemBuilder: (context, index) => SingleChildScrollView(
这是我要显示子集合中数据的地方
Text(
                                  snapshot.data.documents[index]['name'],
                                  style: TextStyle(
                                      fontSize: 20, color: Colors.red[500]),
                                )
数据库database main
database sub

最佳答案

您可以通过访问文档内部的子集合来从集合中获取数据,如下所示

Firestore.instance.collection('singers').document('aryana sayeed').collection('song list').snapshots()
要么
Firestore.instance.collection('singers/aryana sayeed/song list').snapshots()

关于firebase - 如何从Firestore子集合中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63281304/

相关文章:

java - 获取 child 的名字以及 Firebase 数据库中的值

android - 从 firebase android 获取数据时项目终止

dart - Flutter - 泛型函数类型定义错误

android - 为什么Flutter导入提供程序包不起作用?

flutter - 如何更改 flutter 中的文本选择选项?

google-app-engine - 尽管我没有使用 AppEngine 或 Datastore,但我无法在项目上启用 firestore

java - 在Firestore中构造此类数据的正确方法是什么?

timer - 如何在 flutter 中从零开始计数器计时器?

image - Flutter:如何将 Canvas/CustomPainter 保存到图像文件中?

flutter - 为什么我不能在flutter中使用可为空的类型