Dineshkumar
Dineshkumar

Reputation: 370

How to scroll list view builder of expansion tile auto scroll to the end of list in Flutter?

I am implementing a list view builder with the expandable tile of( 6 Nos).I just want to display the end of the list view . I am facing problem with when I am click the fifth expandable tile that detail should hide below the screen. I just want to display automatically without scroll. But I cannot able to use the scroll animation because the expandable tile does not have any on click property. I need some help on this ?

Upvotes: 1

Views: 2038

Answers (1)

Dpedrinha
Dpedrinha

Reputation: 4230

ExpansionTile has a onExpansionChanged property for a callback. You can set this property to a callback like this to scroll to the bottom:

onListExpansionChanged(bool expanded) { //returns if it was expanded (true) or collapsed (false)
    if (expanded) {
      _scrollController.animateTo(_scrollController.position.maxScrollExtent, duration: Duration(milliseconds: 500), curve: Curves.easeIn);
    }
  }

Of course, for that, you need to set the _scrollController:

ScrollController _scrollController;

@override
  void initState() {
    super.initState();
    _scrollController = ScrollController();
  }

and use it on your ListView:

...
ListView(
  controller: _scrollController,
...

or

...
ListView.builder(
  controller: _scrollController,
...

Upvotes: 1

Related Questions