Auto Scrolling in Flutter

Viewed 4518

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 ?

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);
Related