我试图逐个获取文档...我在下面的代码中使用它的工作,但在控制台中它显示我的错误,如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"),)
],
)
],
)
在检查快照是否包含任何数据之前,您尝试访问文档列表的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关键字。