Chairuman
Chairuman

Reputation: 136

How to retrieve all values from Unique Key Firebase in Flutter?

I want to retrieve the value from Firebase unique key in flutter, the Firebase structure is like this

https://i.sstatic.net/CZHve.jpg

here my code

void showTemperature(){
 final databaseRefences = FirebaseDatabase.instance.reference().child("Monitoring").child("s
Suhu");
 databaseReferences.once().then((Datasnapshot snapshot){
  Map <dynamic, dynamic> values = snapshot.value;
  values.forEach((key, values){
    print(value[key]);
   });
 });
}

the output of retrieve data I want is like this

43.70 *c
48.20 *c
33.90 *c
26.10 *c
38.10 *c

anyone can help me to retrieve data like this in flutter?

Upvotes: 0

Views: 1489

Answers (1)

flarkmarup
flarkmarup

Reputation: 5439

So the problem seemed to be caused by minor errors. To conclude, the solution to the problem is the following:

Future<void> showTemperature() async { // making this both a Future and async method
 final databaseRefences = await FirebaseDatabase.instance.reference().child("Monitoring").child("Suhu");
 databaseReferences.once().then((Datasnapshot snapshot){
  Map <dynamic, dynamic> values = snapshot.value;
  values.forEach((key, values){
    print(value); // omitting "[keys]" from the OPs approach
   });
 });
}

Please mark this as the correct solution to your problem and let me know if I this differ from your implemented solution.

Upvotes: 1

Related Questions