我该如何显示文件?

问题描述 投票:1回答:1

我试图逐个获取文档...我在下面的代码中使用它的工作,但在控制台中它显示我的错误,如StreamBuilderBaseState>#de08b):getter'documents'在null上调用。 Receiver:null尝试调用:文档

new StreamBuilder<QuerySnapshot>(
          stream: Firestore.instance.collection("Quiz").where("topice",isEqualTo: widget.topic).where("section",isEqualTo: widget.section).snapshots(),
          builder: (BuildContext context,
              AsyncSnapshot<QuerySnapshot> snapshot,) {
            int length= snapshot.data.documents.length;
            if (!snapshot.hasData)
              return new Container(child: Text(""),);

            return ListView(
              children: <Widget>[
                Text(widget.scoren.toString()),
                Text(snapshot.data.documents[cunter]["Description"]),
                Row(
                  children: <Widget>[
                    CupertinoButton(child: Text("COMMENTS"), onPressed: null),
                    RaisedButton(onPressed: (){
                      setState(() {
                        cunter++;
                      });
//                    Navigator.of(context).push(new MaterialPageRoute(builder: (context)=>new MyApp()));

                    },child: Text("NEXT"),)
                  ],
                )

              ],
            )
flutter google-cloud-firestore
1个回答
1
投票

在检查快照是否包含任何数据之前,您尝试访问文档列表的length属性。

尝试反转这些线,像这样

//Check if the snapshot has data
if (!snapshot.hasData) return Container(child: Text(""));
//If you get here it means you have data
int length= snapshot.data.documents.length;

此外,请记住,在Dart 2中,不再需要qazxsw poi关键字。

© www.soinside.com 2019 - 2024. All rights reserved.