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

flutter get data from firebase
firebase get data
firebase get all child keys javascript
flutter firestore read data
snapshot.val is not a function
firebase get user data
flutter firestore get collection
firebase check if child exists

I have this datasnapshot

 "{post1: {pic:, title: title, desc: desc}, post2: {pic:, 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) {

  _objdatabase = snapshot.value;

return _objdatabase;


here is what i did

Map<dynamic, dynamic> map =;


Flutter, I show two ways to get dat in the initState, 1. get data once and 2. and get updates in import 'package:flutter/material.dart'; .then((DataSnapshot snapshot) {. We assign dbRef.once() which returns a Future<DataSnapshot> to the future property, this will retrieve the data only once. Since this is asychronous, then first the widget CirculareProgressIndicator will be executed, then if the snapshot has data, the code inside the if block will get executed.

What you want is to iterated over values in your snapshot.value and add them to a list.


for (var value in snapshot.value.values){

Then you will be able to do something like this depending on your use case:

myList.forEach((v)=>print(v["pic"].toString)); //just an example

DataSnapshot class - firebase_dart library, Any time you read data from a Firebase database, you receive the data as a DataSnapshot. DataSnapshots are passed to event handlers such as onValue or​  The DataSnapshot's contents as a JavaScript value (Object, Array, string, number, boolean, or null ). for Each ( action: function): boolean. Enumerates the top-level children in the DataSnapshot. Because of the way JavaScript objects work, the ordering of data in the JavaScript object returned by val () is not guaranteed to

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


firebase.database.DataSnapshot, ValueChangedEventArgs contains a DataSnapshot that contains the data at the specified location in the database at the time of the event. Calling Value on a  for accessing the key from DataSnapshot just use snapshot.key and you will have the relative key of the item in your case Users.then((onValue) { => { var key = data.key }) }); or just use as given in firebase docs inside then

This code retrieve the key of node:

DataSnapshot usuario = await messagesRef.limitToLast(10).orderByChild("email").equalTo(mail_emparejar).once()
.then((DataSnapshot snapshot) {


Retrieving Data, A couple of weeks ago I started learning flutter and set out to create a Cookbook. The data is not stored locally, but on my all-time favorite Realtime Database This is a reference to a specific point within the database tree at jsonResponse​=dataSnapshot.value[0]['content']; recipeList = new RecipeList. The second one is that realtime database is a mature product and you can expect the stability, and it’s a tried-and-true product. The third case, it is possible to use both of the databases together within the same Firebase app or project to reduce your firebase bill.

Creating a custom Listview using the Firebase Realtime Database in , data.snapshot.value == null//return sizedbox if there's nothing in database. ? SizedBox()//otherwise return a list of widgets. Firestore get DocumentSnapshot's field's value. you can use get method to get value of a field. You need to do a DocumentReference to get the content in your

Realtime database in flutter - FlutterPub, Inside the if block, we use the property value of type DataSnapshot that will So first you need to order the data by something specific, in the  Fetching data from the internet is necessary for most apps. Luckily, Dart and Flutter provide tools, such as the http package, for this type of work. This recipe uses the following steps: Add the http package. Make a network request using the http package. Convert the response into a custom Dart object. Fetch and display the data with Flutter.

How to use Firebase Queries In Flutter, I have a DataSnapshot JSON object : {fridge2: true, fridge1: true} //data pulled from a real Flutter: The method forEach isn't defined for the class DataSnapshot​. Also, you'd probably get quicker responses about this type of thing (i.e. not an actual bug with flutter but rather a problem you're having) from stackoverflow, the realtime chat channel, or the google group mailing list.