Flutter Firebase Database wrong timestamp order

前端 未结 1 1818
说谎
说谎 2020-12-04 03:25

I\'m trying to set timestamp into firebase realtime database but when I retrieve, not ordering by timestamp. I did like so.

FirebaseDatabase.instance.referen         


        
相关标签:
1条回答
  • 2020-12-04 04:07

    The data is retrieved in the right order into a DataSnapshot. But when you call snap.value the information from the snapshot has to be converted into a Map<String, Object>, which not longer can hold information about the order of the child nodes.

    To maintain the order, you have to process the child nodes from the DataSnapshot with a loop. I'm not an expert in Flutter (at all), but I can't quickly find a way to do this for a value event. So you might want to instead listen for .childAdded:

       FirebaseDatabase.instance
            .reference()
            .child('path')
            .orderByChild('timestamp')
            .onChildAdded
            .listen((Event event) {
          print(event.snapshot.value);
        })
    
    0 讨论(0)
提交回复
热议问题