|
@@ -17,10 +17,6 @@ class StyledScrollbar extends StatefulWidget {
|
|
final bool autoHideScrollbar;
|
|
final bool autoHideScrollbar;
|
|
final Color? handleColor;
|
|
final Color? handleColor;
|
|
final Color? trackColor;
|
|
final Color? trackColor;
|
|
-
|
|
|
|
- // ignore: todo
|
|
|
|
- // TODO: Remove contentHeight if we can fix this issue
|
|
|
|
- // https://stackoverflow.com/questions/60855712/flutter-how-to-force-scrollcontroller-to-recalculate-position-maxextents
|
|
|
|
final double? contentSize;
|
|
final double? contentSize;
|
|
|
|
|
|
const StyledScrollbar(
|
|
const StyledScrollbar(
|
|
@@ -48,25 +44,7 @@ class ScrollbarState extends State<StyledScrollbar> {
|
|
@override
|
|
@override
|
|
void initState() {
|
|
void initState() {
|
|
widget.controller.addListener(() => setState(() {}));
|
|
widget.controller.addListener(() => setState(() {}));
|
|
- widget.controller.position.isScrollingNotifier.addListener(
|
|
|
|
- () {
|
|
|
|
- if (!mounted) return;
|
|
|
|
- if (!widget.autoHideScrollbar) return;
|
|
|
|
- _hideScrollbarOperation?.cancel();
|
|
|
|
- if (!widget.controller.position.isScrollingNotifier.value) {
|
|
|
|
- _hideScrollbarOperation = CancelableOperation.fromFuture(
|
|
|
|
- Future.delayed(const Duration(seconds: 2), () {}),
|
|
|
|
- ).then((_) {
|
|
|
|
- hideHandler = true;
|
|
|
|
- if (mounted) {
|
|
|
|
- setState(() {});
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- hideHandler = false;
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- );
|
|
|
|
|
|
+ _listenOnScrollPositionChanged();
|
|
super.initState();
|
|
super.initState();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -77,6 +55,7 @@ class ScrollbarState extends State<StyledScrollbar> {
|
|
|
|
|
|
@override
|
|
@override
|
|
void didUpdateWidget(StyledScrollbar oldWidget) {
|
|
void didUpdateWidget(StyledScrollbar oldWidget) {
|
|
|
|
+ _listenOnScrollPositionChanged();
|
|
if (oldWidget.contentSize != widget.contentSize) setState(() {});
|
|
if (oldWidget.contentSize != widget.contentSize) setState(() {});
|
|
super.didUpdateWidget(oldWidget);
|
|
super.didUpdateWidget(oldWidget);
|
|
}
|
|
}
|
|
@@ -210,6 +189,27 @@ class ScrollbarState extends State<StyledScrollbar> {
|
|
.clamp(0.0, widget.controller.position.maxScrollExtent));
|
|
.clamp(0.0, widget.controller.position.maxScrollExtent));
|
|
widget.onDrag?.call(details.delta.dy);
|
|
widget.onDrag?.call(details.delta.dy);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ void _listenOnScrollPositionChanged() {
|
|
|
|
+ widget.controller.position.isScrollingNotifier.addListener(
|
|
|
|
+ () {
|
|
|
|
+ if (!mounted) return;
|
|
|
|
+ if (!widget.autoHideScrollbar) return;
|
|
|
|
+
|
|
|
|
+ _hideScrollbarOperation?.cancel();
|
|
|
|
+ if (!widget.controller.position.isScrollingNotifier.value) {
|
|
|
|
+ _hideScrollbarOperation = CancelableOperation.fromFuture(
|
|
|
|
+ Future.delayed(const Duration(seconds: 2), () {}),
|
|
|
|
+ ).then((_) {
|
|
|
|
+ hideHandler = true;
|
|
|
|
+ if (mounted) setState(() {});
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ hideHandler = false;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
class ScrollbarListStack extends StatelessWidget {
|
|
class ScrollbarListStack extends StatelessWidget {
|