Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Scrolling in Flutter

So I have a SingleChildScrollView() whose child is a Column() with different widgets inside it. I have 3 BUTTONS on the app bar. Each for 3 widgets I want to jump to.

When I press the button, I want the UI to automatically scroll to the mapped Widget. Just like we see that effect in websites.

How can I achieve this ?

like image 912
Karan Owalekar Avatar asked Oct 19 '25 05:10

Karan Owalekar


1 Answers

You can create a ScrollController and pass it to the controller parameter of your scrolling widget. Then you can use the animateTo method to animate to an offset.

Ex.

ScrollController controller = ScrollController();

//In build
SingleChildScrollView(
  controller: controller,
  child: ...,
)

//In each button onPressed/onTap
controller.animateTo(offset);
like image 173
Christopher Moore Avatar answered Oct 21 '25 22:10

Christopher Moore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!