flutter
Flutter - ScrollController not attached to any scroll views
May 19, 2023
If you are getting error - ScrollController not attached to any scroll views in your Flutter project then you can you can add the check for _scrollController.hasClients before using ScrollController.
In the below code example we have created a ScrollController in Flutter. If your scroll controller is disposed and you are trying to apply some operations on Scroll Controller then it will raise an exception in your Flutter program.
To avoid it you can use the check _scrollController.hasClients before executing any further tasks.
if (_scrollController.hasClients) {
_scrollController.animateTo(
_scrollController.position.maxScrollExtent,
curve: Curves.easeOut,
duration: const Duration(milliseconds: 300),
);
}
Error - ScrollController not attached to any scroll views
Solution
if (_scrollController.hasClients) {
}
The condition will check whether Scroll Controller has any clients or not in Flutter. If no client is found then the conditional code will now be executed.
Was this helpful?
Similar Posts