4

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
2
  • Are you using a SingleChildScrollView? You don't mention what's doing the scrolling. Commented Aug 2, 2020 at 18:54
  • I just realised that I didnt mention it. And Yes I use SIngleChildScrollView Commented Aug 2, 2020 at 18:59

1 Answer 1

11

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
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.