错误:错误状态:DocumentSnapshotPlatform 中不存在字段

时间:2021-07-09 12:40:01

标签: firebase flutter google-cloud-firestore

我想在我的应用中显示文本。但是出现以下错误:

错误状态:DocumentSnapshotPlatform 中不存在字段

以下是我的代码:

return Scaffold(
        appBar: AppBar(
          iconTheme: IconThemeData(color: Colors.black),
          title: Text('TechFuture',
              style: TextStyle(
                color: Colors.black,
              )),
          backgroundColor: Colors.white,
        ),
        body: StreamBuilder(
            stream: FirebaseFirestore.instance.collection('newfos').snapshots(),
            builder:
                (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
              if (!snapshot.hasData) {
                return Center(
                  child: CircularProgressIndicator(),
                );
              } 

              return ListView(
                children: snapshot.data.docs.map((document) {
                  //if (document.data().containsKey('Bild')) {
                    return Center(
                        child: Container(
                            margin: EdgeInsets.only(bottom: 40),
                            child: InkWell(
                              onTap: () {},
                              child: Stack(
                                children: <Widget>[
                                  Transform.translate(
                                    offset: Offset(0, 246.0),
                                    child: Container(
                                      width: 370.0,
                                      height: 41.0,
                                      decoration: BoxDecoration(
                                        borderRadius:
                                            BorderRadius.circular(10.0),
                                        color: const Color(0xffff0000),
                                        //border: Border.all(
                                        //width: 1.0, color: const Color(Colors.white)),
                                      ),
                                    ),
                                  ),
                                  Transform.translate(
                                    offset: Offset(0, 55.0),
                                    child: Container(
                                      width: 370.0,
                                      height: 213.0,
                                      alignment: Alignment.bottomCenter,
                                      child: Column(children: [
                                        if (document
                                            .data()
                                            .containsKey('Uberschrift'))
                                          Text(
                                            document['Uberschrift'],
                                            style: TextStyle(
                                              fontSize: 22,
                                              color: Colors.yellow,
                                              fontFamily: "Arial",
                                            ),
                                          ),
                                        SizedBox()
                                      ]),
                                      decoration: BoxDecoration(
                                        borderRadius:
                                            BorderRadius.circular(29.0),
                                        image: DecorationImage(
                                          image: NetworkImage((document['Bild'])),
                                          fit: BoxFit.cover,
                                        ),
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            )));
                  }
                //}
                ).toList(),
              );
            }));
  }
}

我希望我的标题在哪里,我用以下行修复了错误:

if(document.data().containsKey('Uberschrift')) 文本(文档['Uberschrift']),

在这种组合中它有效。但是我希望图片显示的地方不起作用。

0 个答案:

没有答案