Created
April 10, 2020 12:49
-
-
Save pskink/516cc94be2e78e1e0bde1c8c775d0af2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AnimatedTransform extends ImplicitlyAnimatedWidget { | |
| const AnimatedTransform({ | |
| Key key, | |
| @required this.transform, | |
| this.alignment = Alignment.center, | |
| this.child, | |
| Curve curve = Curves.linear, | |
| @required Duration duration, | |
| VoidCallback onEnd, | |
| }) : assert(transform != null), assert(alignment != null), | |
| super(key: key, curve: curve, duration: duration, onEnd: onEnd); | |
| final Matrix4 transform; | |
| final AlignmentGeometry alignment; | |
| final Widget child; | |
| @override | |
| _AnimatedTransformState createState() => _AnimatedTransformState(); | |
| @override | |
| void debugFillProperties(DiagnosticPropertiesBuilder properties) { | |
| super.debugFillProperties(properties); | |
| properties.add(DiagnosticsProperty<Matrix4>('transform', transform)); | |
| properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); | |
| } | |
| } | |
| class _AnimatedTransformState extends AnimatedWidgetBaseState<AnimatedTransform> { | |
| AlignmentGeometryTween _alignment; | |
| Matrix4Tween _transform; | |
| @override | |
| void forEachTween(TweenVisitor<dynamic> visitor) { | |
| _transform = visitor(_transform, widget.transform, (dynamic value) => Matrix4Tween(begin: value as Matrix4)) as Matrix4Tween; | |
| _alignment = visitor(_alignment, widget.alignment, (dynamic value) => AlignmentGeometryTween(begin: value as AlignmentGeometry)) as AlignmentGeometryTween; | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Transform( | |
| transform: _transform.evaluate(animation), | |
| alignment: _alignment.evaluate(animation), | |
| child: widget.child, | |
| ); | |
| } | |
| @override | |
| void debugFillProperties(DiagnosticPropertiesBuilder description) { | |
| super.debugFillProperties(description); | |
| description.add(DiagnosticsProperty<Matrix4Tween>('transform', _transform, defaultValue: null)); | |
| description.add(DiagnosticsProperty<AlignmentGeometryTween>('alignment', _alignment, defaultValue: null)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment