I want when someone add new post it should appear on the top of the post.
I also used reverse from listview but it wont worked.
await Future.value(uploadTask);
var newUrl = await ref.getDownloadURL();
final User? user = _auth.currentUser;
postRef.child('Post List').child(date.toString()).set({
'pId': date.toString(),
'pImage': newUrl.toString(),
'pTime': date.toString(),
'pTitle': titleController.text.toString(),
'pDescription': descriptionController.text.toString(),
'uEmail': user!.email.toString(),
'uid': user.uid.toString(),
}).then((value){
toastMessage('Post Published');
setState(() {
showSpinner = false;
});
} ).onError((error, stackTrace) {
toastMessage(error.toString());
setState(() {
showSpinner = false;
});
});
}catch (e) {
setState(() {
showSpinner = false;
});
...
Expanded(child: FirebaseAnimatedList(
query: dbRef.child('Post List'),
scrollDirection: Axis.vertical,
itemBuilder: (BuildContext context, DataSnapshot snapshot, Animation<double> animation, int index) {
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FadeInImage.assetNetwork(image: snapshot.value['pImage'], placeholder: 'assets/x.png',),
SizedBox(height: 5.0),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Text(snapshot.value['pTitle'], style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Text(snapshot.value['pDescription'], style: TextStyle(fontSize: 15, fontWeight: FontWeight.normal), ),
),
SizedBox(height: 20),
],
),
);
}
"reverse: true" add to firebaseanimatedlist
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.