Repository navigation
Wrapping a Scrollbar around a TabBar throws error The Scrollbar's ScrollController has no ScrollPosition attached. #124608
Description
Wrapping a Scrollbar around a TabBar works but throws a console error
The Scrollbar's ScrollController has no ScrollPosition attached.
A Scrollbar cannot be painted without a ScrollPosition.
The Scrollbar attempted to use the PrimaryScrollController. This ScrollController should be associated with the ScrollView that the Scrollbar is being applied to.A ScrollView with an Axis.vertical ScrollDirection on mobile platforms will automatically use the PrimaryScrollController if the user has not provided a ScrollController. To use the PrimaryScrollController explicitly, set ScrollView.primary to true for the Scrollable widget.
The fix described in this commend #97873 (comment) does not work because a tabcontroller cannot be applied to a scrollcontroller
PreferredSize(
preferredSize: const Size.fromHeight(55),
child: RawScrollbar(
//controller: PrimaryScrollController.of(context),
//padding: EdgeInsets.all(5),
mainAxisMargin: 5,
trackVisibility: false,
thumbColor: Theme.of(context).focusColor,
thickness: 3,
thumbVisibility: true,
interactive: false,
scrollbarOrientation: ScrollbarOrientation.top,
child: TabBar(
padding: const EdgeInsets.only(top: 5),
controller: _tabController,
labelPadding: const EdgeInsets.symmetric(horizontal: 20),
//padding: const EdgeInsets.only(top: 5,bottom: 5, left: 5, right: 5),
labelColor: Theme.of(context).colorScheme.primary,
labelStyle: Theme.of(context).textTheme.titleMedium,
isScrollable: true,
unselectedLabelColor:
Theme.of(context).focusColor.withOpacity(0.7),
indicatorColor: Theme.of(context).colorScheme.primary,
tabs: __tabs,
),
),
),
Working with Channel stable, 3.7.10 and the issue appears on all platforms
Activity
darshankawar commentedon Apr 12, 2023
@zogol
TabBarViewis also scrollable, so if you are wrappingScrollbararound it, it might be causing conflict on scroll and hence the error could likely being thrown.Can you provide us your use case for which you need to wrap scrollbar around tabbar ?
Also read this https://api.flutter.dev/flutter/widgets/NestedScrollView-class.html and see if it helps in your use case.
zogol commentedon Apr 13, 2023
The practical example in which I would apply it would be the following.
I have a tabbar with a large number of tabs. and similar to long vertically scrollable lists I would like to show my users an indicator where they are located inside the TabBar.
Recording.2023-04-13.101446.2.mp4
darshankawar commentedon Apr 13, 2023
@zogol
Did you get a chance to look at NestedScrollView and see if it helps in implementing your use case ?
zogol commentedon Apr 21, 2023
@darshankawar .no but i am not a professional in flutter yet either...
i found another practical example right here on the github tabbar which also shows a scroll indicator.
Screen_Recording_20230420_160511_Chrome.mp4
darshankawar commentedon Apr 24, 2023
Thanks for the feedback. Please provide us a minimal code sample that throws the reported error so that we can analyze the issue further.
zogol commentedon May 1, 2023
darshankawar commentedon May 2, 2023
Thanks for the update. Please switch to latest master and try again to see if issue still persists or not. Also check this comment / solution to see if it works in your case or not.
15 remaining items
Ferrb9579 commentedon Oct 8, 2023
Sorry I was lazy to destructure. Hope someone finds it useful
The Scrollbar and ListView must contain same ScrollController.
The ListView Physics should not be defined
Allow TabBar to receive a TabBarScrollController (#180389)
Allow TabBar to receive a TabBarScrollController (flutter#180389)
Allow TabBar to receive a TabBarScrollController (flutter#180389)
github-actions commentedon Mar 4, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.Allow TabBar to receive a TabBarScrollController (flutter#180389)
Allow TabBar to receive a TabBarScrollController (#180389)
Allow TabBar to receive a TabBarScrollController (#180389)