您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
102 行
3.6 KiB
102 行
3.6 KiB
using Unity.UIWidgets.animation;
|
|
using Unity.UIWidgets.async;
|
|
using Unity.UIWidgets.foundation;
|
|
using Unity.UIWidgets.ui;
|
|
using Unity.UIWidgets.widgets;
|
|
|
|
namespace Unity.UIWidgets.material {
|
|
public class Scrollbar : StatefulWidget {
|
|
public Scrollbar(
|
|
Key key = null,
|
|
Widget child = null) : base(key: key) {
|
|
this.child = child;
|
|
}
|
|
|
|
public readonly Widget child;
|
|
|
|
public override State createState() {
|
|
return new _ScrollbarState();
|
|
}
|
|
}
|
|
|
|
public class _ScrollbarState : TickerProviderStateMixin<Scrollbar> {
|
|
public ScrollbarPainter _materialPainter;
|
|
public TextDirection _textDirection;
|
|
public Color _themeColor;
|
|
|
|
public AnimationController _fadeoutAnimationController;
|
|
public Animation<double> _FadeoutOpacityAnimation;
|
|
public Timer _fadeoutTimer;
|
|
|
|
public override void initState() {
|
|
base.initState();
|
|
this._fadeoutAnimationController = new AnimationController(
|
|
vsync: this,
|
|
duration: ScrollbarUtils._kScrollbarFadeDuration
|
|
);
|
|
this._FadeoutOpacityAnimation = new CurvedAnimation(
|
|
parent: this._fadeoutAnimationController,
|
|
curve: Curves.fastOutSlowIn
|
|
);
|
|
}
|
|
|
|
public override void didChangeDependencies() {
|
|
base.didChangeDependencies();
|
|
|
|
ThemeData theme = Theme.of(this.context);
|
|
|
|
this._themeColor = theme.highlightColor.withOpacity(1.0);
|
|
this._textDirection = Directionality.of(this.context);
|
|
this._materialPainter = this._BuildMaterialScrollbarPainter();
|
|
}
|
|
|
|
public ScrollbarPainter _BuildMaterialScrollbarPainter() {
|
|
return new ScrollbarPainter(
|
|
color: this._themeColor,
|
|
textDirection: this._textDirection,
|
|
thickness: ScrollbarUtils._kScrollbarThickness,
|
|
fadeoutOpacityAnimation: this._FadeoutOpacityAnimation
|
|
);
|
|
}
|
|
|
|
bool _handleScrollNotification(ScrollNotification notification) {
|
|
if (notification is ScrollUpdateNotification || notification is OverscrollNotification) {
|
|
if (this._fadeoutAnimationController.status != AnimationStatus.forward) {
|
|
this._fadeoutAnimationController.forward();
|
|
}
|
|
|
|
this._materialPainter.update(notification.metrics, notification.metrics.axisDirection);
|
|
this._fadeoutTimer?.cancel();
|
|
|
|
this._fadeoutTimer = Window.instance.run(ScrollbarUtils._kScrollbarTimeToFade, () => {
|
|
this._fadeoutAnimationController.reverse();
|
|
this._fadeoutTimer = null;
|
|
});
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override void dispose() {
|
|
this._fadeoutAnimationController.dispose();
|
|
this._fadeoutTimer?.cancel();
|
|
this._materialPainter?.dispose();
|
|
|
|
base.dispose();
|
|
}
|
|
|
|
public override Widget build(BuildContext context) {
|
|
return new NotificationListener<ScrollNotification>(
|
|
onNotification: this._handleScrollNotification,
|
|
child: new RepaintBoundary(
|
|
child: new CustomPaint(
|
|
foregroundPainter: this._materialPainter,
|
|
child: new RepaintBoundary(
|
|
child: this.widget.child
|
|
)
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|