animateTo method

void animateTo(
  1. Matrix4 newMatrix, {
  2. Duration duration = const Duration(milliseconds: 150),
  3. Curve curve = Curves.linear,
  4. bool noTranslation = false,
  5. dynamic noZoom = false,
  6. Offset? focalPoint,
})

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();
  }
}