Home > Software engineering >  How to move up scrollable list of selectable items inside GridView.count() in the Flutter?
How to move up scrollable list of selectable items inside GridView.count() in the Flutter?

Time:03-04

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

CodePudding user response:

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

  • Related