0

I have too many selectable iconbuttons list arranged by GridView.count(). I want to change the scroll position (move up) when selecting one of the icon buttons. how can I do that?

Container(
 padding: const EdgeInsets.all(4),
 child: GridView.count(
 childAspectRatio: 0.95,
 padding: const EdgeInsets.symmetric(
 horizontal: 3, vertical: 0),
 crossAxisCount: 4,
 children: <Widget>[...iconButtonsList()],
 ),
)

this is the result of my code :

enter image description here

asked Mar 3, 2022 at 7:02
1
  • It seems like you need to re-order your list after each item selection in a way that it actually shows the selected elements first. Commented Mar 3, 2022 at 7:10

1 Answer 1

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.

ScrollController controller = ScrollController();
//In build
SingleChildScrollView(
controller: controller,
child: ...,
)
//In each icon onPressed/onTap
controller.animateTo(offset);

or you can use this package scroll_to_index: ^2.1.1

All Credit goes to this answer: Auto Scrolling in Flutter

answered Mar 3, 2022 at 7:41
Sign up to request clarification or add additional context in comments.

Comments

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.