animateZoomToPoint method
Animates zooming to a specific offset
and scale
over duration
.
The transition uses the provided curve
to control easing. If offset
or scale
is null, they default to Offset.zero and 1.0 respectively.
Implementation
Future<void> animateZoomToPoint({
Offset? offset,
double? scale,
Duration duration = const Duration(milliseconds: 300),
Curve curve = Curves.easeInOut,
}) async {
if (_animationCtrl.isAnimating) return;
final effectiveOffset = offset ?? Offset.zero;
final effectiveScale = scale ?? 1.0;
final targetMatrix = Matrix4.identity()
..translate(effectiveOffset.dx, effectiveOffset.dy)
..scale(effectiveScale);
final tween = Matrix4Tween(
begin: _transformCtrl.value,
end: targetMatrix,
);
_animationCtrl
..duration = duration
..reset();
final animation = tween.animate(CurvedAnimation(
parent: _animationCtrl,
curve: curve,
));
void listener() {
_transformCtrl.value = animation.value;
}
_animationCtrl.addListener(listener);
await _animationCtrl.forward();
_animationCtrl.removeListener(listener);
}