如何从flutter中的数据快照中获取特定值? [英] How do I get specific values from a datasnapshot in flutter?

查看:101
本文介绍了如何从flutter中的数据快照中获取特定值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此数据快照

 "{post1: {pic: https://i.redd.it/ni6zhxh874011.jpg, title: title, desc: desc}, post2: {pic: https://i.redd.it/krj9miojg5011.jpg, title: awsdas, desc: desc2}}"

,我想从每个帖子中检索 pic值。
snapshot.value [ pic]不起作用,它返回null。

and I would like to retrieve the "pic" values from each post. snapshot.value["pic"] does not work it returns null.

预先感谢

这就是我为未来的构建者接收数据快照的方式

this is how I recieved the datasnapshot for my future builder

Future<Object> _obj ()async {
Object _objdatabase;
await FirebaseDatabase.instance.reference().child("Communities").once().then((DataSnapshot snapshot) {
  print(_objdatabase.toString());

  _objdatabase = snapshot.value;

});
return _objdatabase;

}

推荐答案

这就是我所做的

Map<dynamic, dynamic> map = snapshot.data.snapshot.value;

map.values.toList()[index]["pic"]

这篇关于如何从flutter中的数据快照中获取特定值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆