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 ?
asked Aug 2, 2020 at 18:49
Karan Owalekar
9671 gold badge11 silver badges31 bronze badges
1 Answer 1
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);
answered Aug 2, 2020 at 19:00
Christopher Moore
17.3k11 gold badges52 silver badges63 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
JAgüero
what if you want to access to that scrollController from another page? Let's say, I am in pageTwo and when I press a button I want it to push pageOne and scroll down to a certain position
Explore related questions
See similar questions with these tags.
lang-dart
SingleChildScrollView? You don't mention what's doing the scrolling.