animateTo method
void
animateTo(})
Automatically animates to a new point
Please dont include any focal point tracking in this function, because it is calculated automatically If you do not include translation or zoom, please disable it by setting noTranslation or noZoom to true Please set focalPoint to the position of the zoom if you want to zoom, otherwise set noZoom to true
Implementation
void animateTo(Matrix4 newMatrix,
{Duration duration = const Duration(milliseconds: 150),
Curve curve = Curves.linear,
bool noTranslation = false,
noZoom = false,
Offset? focalPoint}) {
assert(!(noTranslation && noZoom),
"Please dont disable both translation and zoom, because then the animation would be useless");
assert(noZoom || focalPoint != null,
"Please provide a focal point for zooming");
resetAnimation();
if (!noZoom) {
scaleAnimationFocalPoint = focalPoint!;
}
scaleStart = null;
rotationStart = null;
referenceFocalPoint = null;
animation?.removeListener(onAnimate);
scaleAnimation?.removeListener(onScaleAnimate);
controller.reset();
scaleController.reset();
if (!noTranslation) {
Offset translation = getMatrixTranslation(newMatrix);
Offset oldTranslation =
getMatrixTranslation(transformationController!.value);
animation = Tween<Offset>(
begin: oldTranslation,
end: translation,
).animate(CurvedAnimation(
parent: controller,
curve: curve,
));
controller.duration = duration;
}
if (!noZoom) {
double scale = newMatrix.getScaleOnZAxis();
double oldScale = transformationController!.value.getScaleOnZAxis();
scaleAnimation = Tween<double>(begin: oldScale, end: scale)
.animate(CurvedAnimation(parent: scaleController, curve: curve));
scaleController.duration = duration;
}
setToAfterAnimate = getScaled(
position: focalPoint,
matrixZoomedNeedToApplyFocalPointTracking: newMatrix);
scrollbarController?.onScrollStart();
if (!noTranslation) {
animation!.addListener(onAnimate);
controller.forward();
}
if (!noZoom) {
scaleAnimation!.addListener(onScaleAnimate);
scaleController.forward();
}
}