【问题标题】:How to get document details inside a StreamBuilder in Flutter如何在 Flutter 的 StreamBuilder 中获取文档详细信息
【发布时间】:2019-02-25 13:51:33
【问题描述】:

我有一个来自不同用户的食谱集合。我通过 authorId 引用配方的作者,我需要在配方旁边显示作者的名字

            ListView.builder(
              itemCount: snapshot.data.documents.length,
              itemBuilder: (context, index) {
                DocumentSnapshot ds = snapshot.data.documents[index];
                if ('${ds['authorId']}' != null) {
                  String authorName="";
                  String authorId='${ds['authorId']}';
                  print(authorId);
                  Firestore.instance.collection('Authors').document(authorId).get().then((author){
                    print(author.data);
                    if(author.data!=null)authorName=author.data["firstName"];
                  });}

authorId 打印正常,但 author.data 始终为 null 是否可以从构建器内的另一个文档中获取数据?

【问题讨论】:

    标签: flutter google-cloud-firestore


    【解决方案1】:

    我认为您在第 4 行的snapshot.data.documents[index] 之后缺少.data

    【讨论】:

      猜你喜欢
      • 2015-11-14
      • 2021-08-27
      • 2020-11-23
      • 1970-01-01
      • 2014-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-24
      相关资源
      最近更新 更多