gpt4 book ai didi

firebase - Flutter:获取 Firebase 数据库引用子所有数据

转载 作者:IT王子 更新时间:2023-10-29 07:07:42 26 4
gpt4 key购买 nike

我有一个 firebase 数据库 child ,内容如下:

enter image description here

如何在 flutter 中检索它?

我当前的代码:

static Future<Query> queryUsers() async{
return FirebaseDatabase.instance
.reference()
.child("zoom_users")
.orderByChild('name');
}

queryUsers().then((query){
query.once().then((snapshot){
//Now how to retrive this snapshot? It's value data giving a json
});
});

最佳答案

要检索数据,请尝试以下操作:

db = FirebaseDatabase.instance.reference().child("zoom_users");
db.once().then((DataSnapshot snapshot){
Map<dynamic, dynamic> values = snapshot.value;
values.forEach((key,values) {
print(values["name"]);
});
});

首先,您在子节点 zoom_users 处添加引用, 那么因为值返回 data['value']您可以将其分配给 Map<dynamic, dynamic>然后使用 forEach 在 map 内部循环并检索值,例如 name .

检查这个:

https://api.dartlang.org/stable/2.0.0/dart-core/Map/operator_get.html

Flutter: The method forEach isn't defined for the class DataSnapshot

关于firebase - Flutter:获取 Firebase 数据库引用子所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52072948/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com