@@ -17,10 +17,6 @@ class StyledScrollbar extends StatefulWidget {
1717 final bool autoHideScrollbar;
1818 final Color ? handleColor;
1919 final Color ? trackColor;
20-
21- // ignore: todo
22- // TODO: Remove contentHeight if we can fix this issue
23- // https://stackoverflow.com/questions/60855712/flutter-how-to-force-scrollcontroller-to-recalculate-position-maxextents
2420 final double ? contentSize;
2521
2622 const StyledScrollbar (
@@ -48,25 +44,7 @@ class ScrollbarState extends State<StyledScrollbar> {
4844 @override
4945 void initState () {
5046 widget.controller.addListener (() => setState (() {}));
51- widget.controller.position.isScrollingNotifier.addListener (
52- () {
53- if (! mounted) return ;
54- if (! widget.autoHideScrollbar) return ;
55- _hideScrollbarOperation? .cancel ();
56- if (! widget.controller.position.isScrollingNotifier.value) {
57- _hideScrollbarOperation = CancelableOperation .fromFuture (
58- Future .delayed (const Duration (seconds: 2 ), () {}),
59- ).then ((_) {
60- hideHandler = true ;
61- if (mounted) {
62- setState (() {});
63- }
64- });
65- } else {
66- hideHandler = false ;
67- }
68- },
69- );
47+ _listenOnScrollPositionChanged ();
7048 super .initState ();
7149 }
7250
@@ -77,6 +55,7 @@ class ScrollbarState extends State<StyledScrollbar> {
7755
7856 @override
7957 void didUpdateWidget (StyledScrollbar oldWidget) {
58+ _listenOnScrollPositionChanged ();
8059 if (oldWidget.contentSize != widget.contentSize) setState (() {});
8160 super .didUpdateWidget (oldWidget);
8261 }
@@ -210,6 +189,27 @@ class ScrollbarState extends State<StyledScrollbar> {
210189 .clamp (0.0 , widget.controller.position.maxScrollExtent));
211190 widget.onDrag? .call (details.delta.dy);
212191 }
192+
193+ void _listenOnScrollPositionChanged () {
194+ widget.controller.position.isScrollingNotifier.addListener (
195+ () {
196+ if (! mounted) return ;
197+ if (! widget.autoHideScrollbar) return ;
198+
199+ _hideScrollbarOperation? .cancel ();
200+ if (! widget.controller.position.isScrollingNotifier.value) {
201+ _hideScrollbarOperation = CancelableOperation .fromFuture (
202+ Future .delayed (const Duration (seconds: 2 ), () {}),
203+ ).then ((_) {
204+ hideHandler = true ;
205+ if (mounted) setState (() {});
206+ });
207+ } else {
208+ hideHandler = false ;
209+ }
210+ },
211+ );
212+ }
213213}
214214
215215class ScrollbarListStack extends StatelessWidget {
0 commit comments