animateToOffsetAndScale method
Animate the canvas to a new offset and scale
Implementation
Future<void> animateToOffsetAndScale({
required Offset offset,
required double scale,
Duration? duration,
Curve curve = Curves.easeInOut,
}) async {
_stopAnimation();
final anim = AnimationController(
vsync: _ticker!,
duration: duration ?? defaultAnimationDuration,
);
_activeAnimation = anim;
final offsetTween = Tween<Offset>(begin: _gsTopLeftOffset, end: offset);
final scaleTween = Tween<double>(begin: _scale, end: scale);
final curvedAnimation = CurvedAnimation(parent: anim, curve: curve);
final offsetAnimation = offsetTween.animate(curvedAnimation);
final scaleAnimation = scaleTween.animate(curvedAnimation);
anim.addListener(() {
_gsTopLeftOffset = offsetAnimation.value;
_scale = scaleAnimation.value;
markDirty();
});
try {
await anim.forward().orCancel;
} on TickerCanceled {
// A new interaction replaced this animation.
} finally {
curvedAnimation.dispose();
_disposeAnimation(anim);
}
}