Firebase:在地图上迭代

Firebase:在地图上迭代,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我得到了一个名为“inventar”的集合,其中包含一个自动生成值的文档,其中包含一个我想要迭代的映射 请注意,这些键会有所不同,因为用户将指定它 如何迭代该映射,以便在下面列出的表单元格中输出键和值 返回StreamBuilder( 流:FirebaseFirestore.instance .收藏(“发明人”) .其中(“Verfallsdatam”) .snapshots(), 生成器:(BuildContext上下文,异步快照){ if(snapshot.hasError){ 返回文本(

我得到了一个名为“inventar”的集合,其中包含一个自动生成值的文档,其中包含一个我想要迭代的映射

请注意,这些键会有所不同,因为用户将指定它

如何迭代该映射,以便在下面列出的表单元格中输出键和值

返回StreamBuilder(
流:FirebaseFirestore.instance
.收藏(“发明人”)
.其中(“Verfallsdatam”)
.snapshots(),
生成器:(BuildContext上下文,异步快照){
if(snapshot.hasError){
返回文本(“出错”);
}
if(snapshot.connectionState==connectionState.waiting){
返回文本(“加载”);
}
返回列表视图(
子项:snapshot.data.docs.map((documentSnapshot){
var_data=documentSnapshot.data();
返回_data.map((键,值){
返回新表(子表:[
新表格行(儿童:[
新表格单元格(子项:新文本(“Produkt”),
新表格单元格(子项:新文本(“Verfallsdatum”),
]),
//如何在这里迭代?
新表格行(儿童:[
新表细胞(
子项:新文本(键),
),
新表细胞(
子项:新文本(值),
),
])
]);
}).toList();
}).toList(),
);
},
);

谢谢您的回复!如果使用您的代码,我会收到一条错误消息“没有为“AsyncSnapshot”类型定义getter“docs”。请尝试导入定义“docs”的库,将名称更正为现有getter的名称,或定义名为“docs”的getter或字段。除此之外,我认为,您的代码将为映射中的每个条目生成一个新表,不幸的是,这不是我想要的。此api
FirebaseFirestore.instance.collection(“inventar”)。其中(“verfallsdatum”).snapshots()
将从集合中返回多个文档,该集合是
QuerySnapshot
的实例,而且它应该有
.docs
getter,它将返回
列表
如果这不是你的情况,你能发布你使用的cloud\u firestore是什么版本的
cloud\u firestore:^0.16.0
哦,我的错应该是
快照.data.docs.map
不是
快照.docs.map
我刚刚做了更正Hi Ara,我刚刚试过你的方法,但有几个错误。首先,ListView小部件的children属性表示“不能将参数类型'List'分配给参数类型'List'”和“不能无条件地访问属性'docs',因为接收方可以为'null'。其次,返回表的行表示“根据闭包上下文的要求,返回类型‘Table’不是‘MapEntry’”。不要认为我们走的是正确的道路。
new StreamBuilder<QuerySnapshot>(
                stream: FirebaseFirestore.instance
                    .collection("inventar")
                    .where("verfallsdatum")
                    .snapshots(),
                builder: (BuildContext context,
                    AsyncSnapshot<QuerySnapshot> snapshot) {
                  if (snapshot.hasError) {
                    return Text('Something went wrong');
                  }

                  if (snapshot.connectionState == ConnectionState.waiting) {
                    return Text("Loading");
                  }

                  return new Table(
                    children: [
                      new TableRow(children: [
                        new TableCell(child: new Text("Produkt")),
                        new TableCell(child: new Text("Verfallsdatum")),
                      ]),

                      // how to iterate here?

                        new TableRow(
                          children: [
                            new TableCell(
                              child: new Text("key"),
                            ),
                            new TableCell(
                              child: new Text("value"),
                            ),
                          ]
                        )
                    ]);
                },
              )
    var products = await db.collection("inventar").doc("vqQXArtqnFyAlkPC1PHr").get().then((snapshot) => {
  snapshot.forEach((doc) => {

  })
});
 return StreamBuilder(
      stream: FirebaseFirestore.instance
          .collection("inventar")
          .where("verfallsdatum")
          .snapshots(),
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (snapshot.hasError) {
          return Text('Something went wrong');
        }

        if (snapshot.connectionState == ConnectionState.waiting) {
          return Text("Loading");
        }

        return ListView(
          children: snapshot.data.docs.map((documentSnapshot) {
            var _data = documentSnapshot.data();

            return _data.map((key, value) {
              return new Table(children: [
                new TableRow(children: [
                  new TableCell(child: new Text("Produkt")),
                  new TableCell(child: new Text("Verfallsdatum")),
                ]),

                // how to iterate here?

                new TableRow(children: [
                  new TableCell(
                    child: new Text(key),
                  ),
                  new TableCell(
                    child: new Text(value),
                  ),
                ])
              ]);
            }).toList();
          }).toList(),
        );
      },
    );