简体   繁体   English

如何从 Flutter 中的唯一键 Firebase 检索所有值?

[英]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我想在flutter中从Firebase唯一键中检索值,Firebase结构是这样的

https://imgur.com/xjG1Q4O https://imgur.com/xjG1Q4O

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 43.70 *c
48.20 *c 48.20 *c
33.90 *c 33.90 *c
26.10 *c 26.10 *c
38.10 *c 38.10 *c

anyone can help me to retrieve data like this in flutter?谁能帮我在颤振中检索这样的数据?

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.请将此标记为您问题的正确解决方案,如果我与您实施的解决方案不同,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM