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 :
asked Mar 3, 2022 at 7:02
Hossein Vejdani
1,10810 silver badges20 bronze badges
-
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.salihgueler– salihgueler2022年03月03日 07:10:36 +00:00Commented Mar 3, 2022 at 7:10
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.
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
Ali Punjabi
5506 silver badges20 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-dart