Flutter error: 'ScrollController not attached to any scroll views.' on scroll
check controller does not have client ant then delay jump:
if (!_scrollController.hasClients) {
_scrollController.animateTo(_scrollController.position.maxScrollExtent,
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut);
}
The problem is inside _scrollListener
.
When you are checking controllers in if-else
there is only one view at the scene. Means only one listview
is rendered & only one scrollcontroller
is completely setup. But in your code they are checking all scrollcontroller's positions in single function. Thats why you are getting this error. First check if controller have the positions, which it will only have if the controller is attached & view is rendered correctly. After that check for extentAfter
value.
Exa -
if (hController.positions.length > 0 && tController.position.extentAfter == 0.0) {
}
else if (tController.positions.length > 0 && tController.position.extentAfter == 0.0) {
}
& so on
To avoid such type of errors use the getter
ScrollController.hasClient
If this is false, then members that interact with the [ScrollPosition],such as [position], [offset], [animateTo], and [jumpTo], must not be called.
for example:
if (_controller.hasClients) {
_controller.animateTo(
...
}