【发布时间】:2018-09-13 17:34:17
【问题描述】:
我正在尝试一个一个地获取文档...我在下面的代码中使用它的工作,但在控制台中它向我显示错误,例如 StreamBuilderBaseState>#de08b): 在 null 上调用了 getter 'documents'。 接收方:空 尝试调用:文档
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"),)
],
)
],
)
【问题讨论】:
-
您是否尝试过构建文档地图,例如“snapshot.data.documents.map
- ”并将数据保存在变量中,然后返回小部件。我认为问题在于“documents [cunter] [“Description”]”行我今天无法对其进行测试,如果找到解决方案,我会继续更新。但首先尝试通过不直接在 StreamBuilder 中返回 ListView 而是使用函数返回小部件来分离代码
标签: flutter google-cloud-firestore