The right way to interact between widgets in flutter is Provider. But Provider manages a data, but with just scrolling, no data is supposed to be changed. How is it possible to send a scroll command (like jumpTo) between widgets placed on same level? (not like parent\child relation)
For example: there is a button that adds a new item to the ListView with provider like that:
listProvider.createItem("New item");
And the list should be scrolled down to the end after that.
How to do that?
CodePudding user response:
Assuming you have access to the scrollController provided to the listView:
You can call scrollController.position.moveTo(scrollcontroller.position.maxScrollExtent) after you've added the element to the ListView.
You can also add a duration to moveTo to get to scroll down more naturally.
CodePudding user response:
Widget A{
@override build (ctx){
return B(_scrollController) ;
}
Widget B{
ScrollController scrollController;
B{this._scrollController}
}
Use this right after listProvider.createItem("New item") to scroll to bottom of listview.
_scrollController.animateTo(_scrollController.position.maxScrollExtent)
