简体   繁体   中英

Why is the data not correctly fetched from the realtime database?

this is my code:

DatabaseReference starCountRef =
        FirebaseDatabase.instance.ref('temp/${widget._tmep}/temp');
    starCountRef.onValue.listen((DatabaseEvent event) {
      final snapshot = event.snapshot.value;
      if (snapshot != null) {
        Object? temp = snapshot;
        print(temp);
...

In the print statement, I receive the:

flutter: [null, false, false, false, false, false, false, false, false, false, false]

But, my real-time database is the following:

在此处输入图像描述

It does not give me: {1,2,3,4,5,6,7,8,9,10}. Can anyone tell me how to solve it?

When the Firebase SDKs find sequential, numeric values in keys they may interpret them as an array. That is exactly what you have here, the SDK interprets your boolean values as an array and adds an empty value at index 0.

There is no way to configure this behavior. A common workaround is to prefix the values with a short, alphanumeric prefix on the numeric values, eg key_1 , key_2 , etc.

Also see: Best Practices: Arrays in Firebase .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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