'Flutter The Scrollbar's ScrollController has no ScrollPosition attached
I get this error when using the AppBar:
The Scrollbar's ScrollController has no ScrollPosition attached.
This is my CustomScrollBar:
class CustomScrollBar extends StatelessWidget {
final Widget child;
final ScrollController scrollController;
const CustomScrollBar({
required this.scrollController,
required this.child,
});
@override
Widget build(BuildContext context) {
return RawScrollbar(
thumbColor: AppColors.gray,
radius: Radius.circular(8),
thickness: 4,
isAlwaysShown: true,
controller: scrollController,
child: child,
);
}
}
I should be always visible. And this is how I use it:
child: CustomScrollBar(
scrollController: _scrollControllerForScrollBar,
child: SingleChildScrollView(
controller: _scrollControllerForScrollBar,
child: Padding(
padding: EdgeInsets.all(7.0.scaled),
child: Container(
width: double.infinity,
child: Text(
'any text bla bla bla \n\n\n this is a lot of \n text \n .'
),
),
),
),
),
As you can see both the ScrollBar and the SingleChildScrollView use the same ScrollController. I have no idea why this error occurs. Any idea what I am missing here?
Solution 1:[1]
I was using a ScrollBar with a ListView widget and was getting this error in the debug console. To get rid of it, I had to set the ScrollController on both widgets.
final yourScrollController = ScrollController();
Scrollbar(
isAlwaysShown: true,
thickness: 10,
controller: yourScrollController, // Here
child: ListView.builder(
padding: EdgeInsets.zero,
scrollDirection: Axis.vertical,
controller: yourScrollController, // AND Here
itemCount: yourRecordList?.length
....
)
)
Solution 2:[2]
Remove the scrollController entirely and that should fix the problem. that is how I fixed my code so your code should look something like this
class CustomScrollBar extends StatelessWidget {
final Widget child;
const CustomScrollBar({
required this.child,
});
@override
Widget build(BuildContext context) {
return RawScrollbar(
thumbColor: AppColors.gray,
radius: Radius.circular(8),
thickness: 4,
isAlwaysShown: true,
child: child,
);
}
}
and the second part should be like this
child: CustomScrollBar(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(7.0.scaled),
child: Container(
width: double.infinity,
child: Text(
'any text bla bla bla \n\n\n this is a lot of \n text \n .'
),
),
),
),
),
Solution 3:[3]
The following assertion was thrown during a scheduler callback: The Scrollbar's ScrollController has no ScrollPosition attached
A Scrollbar cannot be painted without a ScrollPosition.
The Scrollbar attempted to use the provided ScrollController. This ScrollController should be associated with the ScrollView that the Scrollbar is being applied to. When providing your own ScrollController, ensure both the Scrollbar and the Scrollable widget use the same one.
This is flutter's bug, https://github.com/flutter/flutter/issues/82573.
It is fixed on the flutter master branch:
flutter channel master
flutter upgrade
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | wilhit |
| Solution 3 | ouflak |
