Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollController not attached to any scroll views

Tags:

flutter

I'm using CustomScrollView, and providing it with a controller. ScrollController works, I even added a listener to it and print out the position of the scroll view.

CustomScrollView(     controller: _scrollController, 

Now, all i'm trying to do is jump to position 50.0 inside initState() function.

_scrollController.jumpTo(50.0); 

But, i get the error

scrollController not attached to any scroll views

like image 770
Omar Awamry Avatar asked Aug 31 '18 11:08

Omar Awamry


People also ask

How do I add a scroll bar in flutter?

Scrollbar is a material widget in flutter that indicates to the user how lengthy the view is. It has a thumb that indicates how long the user has scrolled either from top or bottom. To display a scrollbar for a scrollview we have to add the scrollview as a child to scrollbar widget.

How do I make my screen not scroll on flutter?

You should use ListView. builder in place of the inner column (as I suggested above that columns are not scrollable). Set shrinkWrap: true, and physics: ClampingScrollPhysics() inside ListView.


1 Answers

Check if the scrollController is attached to a scroll view by using its hasClients property first.

if (_scrollController.hasClients)      _scrollController.jumpTo(50.0); 
like image 81
Ed H Avatar answered Sep 21 '22 19:09

Ed H