India Office
Office No. 501, Shree Ugati Corporate Park, Gandhinagar - 382421, Gujarat, India
[email protected]
How to Solve Scroll Controller Could Not Attached to Any Scroll Views In Flutter ?
A
ScrollBar Widget
that can be dragged for quickly navigation through a vertical list. A
ScrollBar Widget
indicates which portion of a
Scrollable Widget
is actually visible. In this article, we will go through How to solve Scroll Controller could not attach to any Scroll Views In Flutter?
How to Solve Scroll Controller Could Not be Attached to Any Scroll Views In Flutter?
Users need to check if the
ScrollController
is attached to a scroll view by using its client’s property first.
if (_scrollController.hasClients)
_scrollController.jumpTo(50.0);
To set the initial position of a ScrollController, use the initialScrollOffset property:
_scrollController = ScrollController(initialScrollOffset: 50.0);
Delaying it is not the right solution. Better to wait till the tree is done building by using the below code snippet.
WidgetsBinding.instance
.addPostFrameCallback((_){});
Users can also try giving below code snippets
@override
void initState(){
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_){
//write or call your logic
//code will run when widget rendering complete
This sometimes happens when you are attempting to bind a ScrollController to a widget that doesn’t actually exist (yet). So it attempts to bind, but there is no ListView/ScrollView to bind to.
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
flex: 8,
child: Container(
child: ListView.builder(
controller: scrollController,
itemCount: messages.length,
itemBuilder: (context, index) {
return MessageTile(message: messages[index]);
first, declare the ListView and ScrollController
final scrollController = ScrollController(initialScrollOffset: 0);
ListView list = ListView.builder(
controller: scrollController,
itemCount: messages.length,
itemBuilder: (context, index) {
return MessageTile(message: messages[index]);
then inside your build function just reference the already built list
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
flex: 8,
child: Container(
child: list,
Future.delayed(Duration(milliseconds: <some time, ex: 100>), () {
_scrollController.jumpTo(50.0);
Initialize the scrollController:
ScrollController _scrollController = ScrollController();
Use the code below where you want to scroll:
SchedulerBinding.instance.addPostFrameCallback((_) {
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
Conclusion:
In this article, we have been through How to solve the scroll controller could not attach to any scroll views in Flutter?
Thanks for Reading !!!
Keep Learning !!! Keep Fluttering !!!
Do share your valuable suggestion feedback for the same.
FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget Guide, Flutter Projects, Code libs and etc.
FlutterAgency.com is one of the most popular online portal dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie | Duration | Description |
---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |