I’m using https://pub.dev/packages/infinite_scroll_pagination for a messaging app I’m developing. It works well, but I’m showing the latest message on the top, and the oldest on the bottom: by scrolling the older messages are loaded.
In order to make it more UX friendly, I would like to sort the messages the other way, like a normal IM one: I want to load the latest messages sorted by time ASC, and load the previous messages when scrolling up.
Is there a library that could me help out with this? How could I develop this?
2
Answers
Would highly recommend using the ListView widget and Streams with the
position.maxScrollExtent
andposition.pixels
attributes from the ScrollController classYou can try setting the
reverse
flag to true into the ListView widget (which is false by default), or manually reverse your array by usinglist.reversed.toList();
Find more about Streams and ListView widget on:
https://dart.dev/tutorials/language/streams
https://api.flutter.dev/flutter/widgets/ListView-class.html
Yes, indeed, it sounds like the dash_chat_2 package could be a great fit for your needs.
It is a comprehensive chat UI package for Flutter with lots of customization options. You can easily configure the message collection to load in descending order, from the most recent to older ones, giving your users that expected messaging experience. When the user scrolls up, previous messages are loaded.
It also includes features such as quick reply suggestions and attachment support.
#Installation:
With Flutter:
This will add a line like this to your package’s pubspec.yaml (and run an implicit
flutter pub get
):Alternatively, your editor might support
flutter pub get
. Check the docs for your editor to learn more.#Implementation:
For more detail you can visit dash_chat_2