【发布时间】:2019-10-26 01:51:58
【问题描述】:
我正在尝试将我的数据放入 Firestore,其中该数据是数组,并将该数据输出到卡片中。截至目前,我得到的输出是“null”。获取此数据数组的最佳方法是什么?我正在使用StreamBuilder<QuerySnapshot> 获取数据。
这是我的代码:
StreamBuilder<QuerySnapshot>(
stream: db.collection('ACTIVITIES').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children: snapshot.data.documents
.map((doc) => buildItem(doc))
.toList());
} else {
return SizedBox();
}
})
这里是我尝试输出数据的地方:
Card buildItem(DocumentSnapshot doc) {
return Card(
elevation: 5,
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Name: ${doc.data['Name_ofUser']}',
style: TextStyle(fontSize: 20),
),
Text(
'Description: ${doc.data['Help_Description']}',
style: TextStyle(fontSize: 20),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlatButton(
color: Color(0xFF121A21),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
onPressed: () {},
child: Text(
'Respond',
style: TextStyle(color: Colors.white, fontSize: 12),
),
),
SizedBox(
width: 5,
),
FlatButton(
color: Color(0xFF121A21),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
onPressed: () {},
child: Text(
'Read',
style: TextStyle(color: Colors.white, fontSize: 12),
),
)
],
),
],
),
),
);
}
这是我的数据库结构:
【问题讨论】:
标签: flutter dart google-cloud-firestore