[英]How to get data from a list field in Firebase?
I am using a ListView.builder
to show the data of all the documents on one page in my app.我正在使用
ListView.builder
在我的应用程序的一页上显示所有文档的数据。 So, how can I make a ListView
inside a ListView
to show all data of the internal array called drinks?那么,如何在
ListView
中创建一个ListView
来显示名为drinks 的内部数组的所有数据?
You can handle this with FutureBuilder if you want.如果需要,您可以使用 FutureBuilder 处理此问题。
FutureBuilder(
future: FirebaseFirestore.instance
.collection('yourCollectionPath')
.doc('yourDocPath')
.get(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData &&
snapshot.connectionState == ConnectionState.done) {
var data = snapshot.data.data();
var drinks = data['drinks'];
return ListView.builder(
shrinkWrap: true,
itemCount: drinks.length,
itemBuilder: (BuildContext context, int index) {
return Text(drinks[index].toString());
},
);
} else {
return Text("Error");
}
},
),
I have to mention that there are so many way to handle with this situation.我不得不提到,有很多方法可以处理这种情况。 This one is the simplest way.
这是最简单的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.