如何从firebase firestore数据库生成小部件列表?

如何从firebase firestore数据库生成小部件列表?,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我试图弄清楚如何在firestore中迭代文档,并为每个文档创建一个文本小部件 我已经知道如何访问这些元素。我使用了debugPrint()并得到了我期望的结果,但我无法让它显示在我的其他小部件下面。我(在手机上)看到一个红色屏幕,上面有大量错误。下面是我迄今为止尝试的代码 QuerySnapshot querySnapshot = await Firestore.instance.collection("users").document(user.uid).collection("t

我试图弄清楚如何在firestore中迭代文档,并为每个文档创建一个文本小部件

我已经知道如何访问这些元素。我使用了debugPrint()并得到了我期望的结果,但我无法让它显示在我的其他小部件下面。我(在手机上)看到一个红色屏幕,上面有大量错误。下面是我迄今为止尝试的代码


   QuerySnapshot querySnapshot = await 
Firestore.instance.collection("users").document(user.uid).collection("trails").getDocuments();
        var list = querySnapshot.documents;
list.forEach((doc) =>  debugPrint(doc.data["Trail Name"].toString()));//works
final topContentText = Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
      //these widgets are generating correctly  
      Text(
          "First Name: $firstName",
          style: TextStyle(color: Colors.white, ),
        ),
        Text(
          "Last Name: $lastName",
          textAlign: TextAlign.left,
          style: TextStyle(color: Colors.white,),
        ),
        Text(
          "Email: $email",
          style: TextStyle(color: Colors.white, ),
        ),
     //these ones are causing my errors.
    list.forEach((doc) =>  Text(
      "Trail Name: ${doc.data["Trail Name"].toString()}",
      style: TextStyle(color: Colors.white, ),
    ),)
      ],
    );

    final topContent = Stack(
      children: <Widget>[
        Container(
          height: MediaQuery.of(context).size.height * 0.40,
          padding: EdgeInsets.all(40.0),
          width: MediaQuery.of(context).size.width,
          decoration: BoxDecoration(color: Color.fromRGBO(58, 66, 86, .9)),
          child: Center(
            child: topContentText,
          ),
        ),
        Positioned(
          left: 8.0,
          top: 60.0,
          child: InkWell(
            onTap: () {
              Navigator.pop(context);
            },
            child: Icon(Icons.arrow_back, color: Colors.white),
          ),
        )
      ],
    );
    return Scaffold(
      body: Column(
        children: <Widget>[topContent, bottomContent],
      ),
    );


QuerySnapshot QuerySnapshot=等待
Firestore.instance.collection(“users”).document(user.uid).collection(“trails”).getDocuments();
var list=querySnapshot.documents;
list.forEach((doc)=>debugPrint(doc.data[“Trail Name”].toString())//作品
最终topContentText=列(
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
//这些小部件正在正确生成
正文(
“名字:$firstName”,
样式:TextStyle(颜色:Colors.white,),
),
正文(
“姓氏:$lastName”,
textAlign:textAlign.left,
样式:TextStyle(颜色:Colors.white,),
),
正文(
“电子邮件:$Email”,
样式:TextStyle(颜色:Colors.white,),
),
//这些导致了我的错误。
list.forEach((doc)=>文本(
“Trail Name:${doc.data[“Trail Name”].toString()}”,
样式:TextStyle(颜色:Colors.white,),
),)
],
);
最终topContent=堆栈(
儿童:[
容器(
高度:MediaQuery.of(上下文).size.height*0.40,
填充:所有边缘设置(40.0),
宽度:MediaQuery.of(context).size.width,
装饰:盒子装饰(颜色:color.fromRGBO(58,66,86,9)),
儿童:中心(
child:topContentText,
),
),
定位(
左:8.0,
排名:60.0,
孩子:InkWell(
onTap:(){
Navigator.pop(上下文);
},
子:图标(Icons.arrow\u back,颜色:Colors.white),
),
)
],
);
返回脚手架(
正文:专栏(
children:[topContent,bottomContent],
),
);

当我希望我的设备在其他信息下方显示轨迹名称时,它的屏幕会因创建子窗口小部件时出现错误而亮起红色。我只包含了必要的代码,但如果需要,还可以包含更多的代码(比如小部件的构建方法)。谢谢你的帮助。我不熟悉颤振。

尝试使用贴图功能:

  List<Widget> _widgets = list.map((doc) =>  Text(
    "Trail Name: ${doc.data["Trail Name"].toString()}",
    style: TextStyle(color: Colors.white, ),
  ),).toList();

啊哈,就是这样。谢谢
children: [ ... ] + _widgets;