简体   繁体   English

如何从 Firebase 的列表字段中获取数据?

[英]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.

相关问题 如何从 firebase 中获取带有字段值的数据? - How to get data from firebase with field value? 如何从refrenced文档(Firebase)中的字段获取String数据 - How to get String data from field inside a refrenced document (Firebase) 如何从 Firebase (Firestore) 获取数据到 Flutter 中的模型列表中? - How to get data from Firebase (Firestore) into list of models in Flutter? 如何从 Firebase 实时数据库中获取数据到 Flutter 的列表中? - How to get data from Firebase Realtime Database into list in Flutter? 如何从 firebase 获取数据并将其存储到列表中以供在 dart 中进一步操作 - How to get data from the firebase and store it into a list for futher manipulation in dart 从 Firebase 获取数据到列表为空(Flutter) - Get data from Firebase to List is null (Flutter) 如何从Firebase实时数据库获取数据并更改一个文本字段以表示该特定记录? - How do I get data from a firebase realtime database and change one text field to represent that specific record? 无法从 firebase 中的参考字段获取数据(颤振) - Can not get data from reference field in firebase (flutter) 如何获取列表<model>来自 Flutter 中的 firebase</model> - How to get List<Model> from firebase in Flutter 如何使用Firebase中的数据对列表进行排序? - How to sort a list with data from Firebase?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM