Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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((_) {
          scrollController.jumpTo(scrollController.position.maxScrollExtent);
        });

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

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

Find more about /ScrollController/animateTo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading