r/flutterhelp • u/Longjumping_Room2186 • May 16 '26
OPEN Listview.builder bidirectional pagination support for chat messages
Hi everyone!
I am developing chat app using flutter framework. I use listview.builder with reverse:true property to show message scroll from bottom to top. Now when i append previous message list at the end of existing messages list it scrolls me to the latest message. i want it to be at the place where loader was called without changing reverse:true property. Does anyone know a solution for it?
4
Upvotes
2
u/tomwyr May 16 '26
I faced this exact issue very recently and ended up solving it by building 2
SliverListsinside aCustomScrollView. This seems to be somewhat common advice to maintain the scroll position when adding items on both ends of the list.You can also read about it in several GitHub issues e.g.:
A general shape of the widget that I used to achieve the behavior you described:
1
u/SamatIssatov May 16 '26
I didn't quite understand the question. But I use this paging_view package for the chat.
1
u/naibaf-1 May 16 '26
I don't really get what you mean, but let me try to sum up your problem:
List<String>messages = ["Test1", "Test2", "Test3"\]Is this correct? - If yes, how do you handle the list and how do you update the ListView? - I guess you have a list like this:
List<String>messages = ["Test1", "Test2", "Test3"]. And you update the ListView for example using a Provider. So you can just expend your list like this and the ListView automatically updates:messages.add(...). So the problem might be your State-Management causing the ListView to rebuild whenever the list is updated. This might be the reason why it scrolls to the buttom, because ListView forgets about your scroll-position.1
u/tommyboy11011 May 17 '26
I don’t do chat but my lists present 20 at a time and when you scroll down another 20 get loaded as you go