Skip to content

Instantly share code, notes, and snippets.

@pskink
Created April 10, 2020 12:49
Show Gist options
  • Select an option

  • Save pskink/516cc94be2e78e1e0bde1c8c775d0af2 to your computer and use it in GitHub Desktop.

Select an option

Save pskink/516cc94be2e78e1e0bde1c8c775d0af2 to your computer and use it in GitHub Desktop.
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