Flutter ScrollController in ListView

I made a chat app in flutter . i want when i open the chat page automatic scroll to the last message like real whats app or messenger . i want when i open the page i be in the last message . i dont want to use reverse in list View

i tried to do this in innit state but it didn’t work when i open the chat page for first time but after that it work fines

WidgetsBinding.instance.addPostFrameCallback((_) {

>Solution :

Using jumpTo will instancly move to bottom after 1st frame is build. You can include a FutureDelay(..) but .animateTo looks better.

  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      await scrollController.animateTo(
          duration: Duration(seconds: 1),
          curve: Curves.bounceIn);

Find more about /ScrollController/animateTo

Leave a Reply