I wanna fetch recent inserted data in firebase realtime database

Viewed 21

I wanna fetch recent inserted data in firebase real-time database, it can be on a top or bottom. basically I have created a card in flutter, instead of list of data I wanna replace the recent inserted database in a app with old data.


Query dbref = FirebaseDatabase.instance.ref().child("post");




Container(
                height: 200,
                  width: 400,
                  child:   FirebaseAnimatedList(
                      query: dbref,
                      itemBuilder: (BuildContext context,DataSnapshot snapshot,Animation<double> animation,int index)
                      {
                        Map data = snapshot.value as Map;
                        data['key'] = snapshot.key;

                        // return ListTile(
                        // title: Text(data[0]["title"].toString()),
                        //    );



                        return li(data:data);

                      }
                  )
              )
1 Answers

The listener receives a DataSnapshot that contains the data at the specified location in the database at the time of the event in its value property.

DatabaseReference starCountRef =
       FirebaseDatabase.instance.ref().child("post");
starCountRef.onValue.listen((DatabaseEvent event) {
    final data = event.snapshot.value;
    updateStarCount(data);
}); 
Related