Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get specific values from a datasnapshot in flutter?

I have this datasnapshot

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

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

thanks in advance

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;
}    
like image 501
Daniel Avatar asked May 27 '18 17:05

Daniel


2 Answers

here is what i did

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

map.values.toList()[index]["pic"]
like image 199
Daniel Avatar answered Sep 22 '22 21:09

Daniel


if you are sure snapshot have child's use value member as Map Object

snapshot.value['key'];
like image 20
Mahmoud Abu Alheja Avatar answered Sep 22 '22 21:09

Mahmoud Abu Alheja