【发布时间】:2021-05-28 21:53:13
【问题描述】:
我有一个颤振项目,我在其中显示产品及其信息,但在 firebase 中,我将图像类型从字符串转换为数组,并且由于类型更改而遇到问题。在另一堂课中,我有相同的示例,但仅限于一个文档,不适用于我的案例。
void getImage() async {
await FirebaseFirestore.instance
.collection('Product')
.doc(docID)
.get()
.then((document) {
imageLists = document.data()['image'];
});
}
有没有办法让这段代码接受数组类型?
StreamBuilder<QuerySnapshot>(
stream: product.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Flexible(
child: GridView.builder(
itemCount: snapshot.data.docs.length,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.fromLTRB(8, 16, 8, 0),
child: Image.network(
// here
snapshot.data.docs[index].get('image'),
width: 150,
height: 120,
),
);
}),
);
}
}),
【问题讨论】:
标签: firebase flutter google-cloud-firestore