Yea*_*508 0 dart firebase firebase-realtime-database flutter
我有一个firebase数据库子级,其内容如下:
如何在扑扑中找回呢?
我当前的代码:
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
});
});
Run Code Online (Sandbox Code Playgroud)
要检索数据,请尝试以下操作:
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"]);
});
});
Run Code Online (Sandbox Code Playgroud)
在这里,您首先在child处添加了引用zoom_users,然后由于可以返回值data['value'],因此可以将其分配给它Map<dynamic, dynamic>,然后使用forEachexample并在其中检索值来在地图内循环name。
检查一下:
https://api.dartlang.org/stable/2.0.0/dart-core/Map/operator_get.html
Flutter:未为DataSnapshot类定义forEach方法
| 归档时间: |
|
| 查看次数: |
5558 次 |
| 最近记录: |