我有一个 firebase 数据库 child ,内容如下:
如何在 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/