onScaleEnd method

  1. @protected
void onScaleEnd(
  1. ScaleEndDetails details, {
  2. bool outer = false,
})

Handle the end of a gesture of _GestureType. All of pan, scale, and rotate are handled with GestureDetector's scale gesture.

Implementation

@protected
void onScaleEnd(ScaleEndDetails details, {bool outer = false}) {
  scaleStart = null;
  rotationStart = null;
  referenceFocalPoint = null;

  animation?.removeListener(onAnimate);
  scaleAnimation?.removeListener(onScaleAnimate);
  controller.reset();
  scaleController.reset();

  if (!gestureIsSupported(gestureType, outer: outer)) {
    currentAxis = null;
    scrollbarController?.onScrollEnd();
    return;
  }

  if (gestureType == GestureType.pan) {
    if (details.velocity.pixelsPerSecond.distance < kMinFlingVelocity) {
      currentAxis = null;
      scrollbarController?.onScrollEnd();
      return;
    }
    final Vector3 translationVector =
        transformationController!.value.getTranslation();
    final Offset translation =
        Offset(translationVector.x, translationVector.y);
    final FrictionSimulation frictionSimulationX = FrictionSimulation(
      widget.interactionEndFrictionCoefficient,
      translation.dx,
      details.velocity.pixelsPerSecond.dx,
    );
    final FrictionSimulation frictionSimulationY = FrictionSimulation(
      widget.interactionEndFrictionCoefficient,
      translation.dy,
      details.velocity.pixelsPerSecond.dy,
    );
    final double tFinal = getFinalTime(
      details.velocity.pixelsPerSecond.distance,
      widget.interactionEndFrictionCoefficient,
    );
    animation = Tween<Offset>(
      begin: translation,
      end: Offset(frictionSimulationX.finalX, frictionSimulationY.finalX),
    ).animate(CurvedAnimation(
      parent: controller,
      curve: Curves.decelerate,
    ));
    controller.duration = Duration(milliseconds: (tFinal * 1000).round());
    animation!.addListener(onAnimate);
    controller.forward();
  } else if (gestureType == GestureType.scale) {
    if (details.scaleVelocity.abs() < 0.1) {
      currentAxis = null;
      scrollbarController?.onScrollEnd();
      return;
    }
    final double scale = transformationController!.value.getScaleOnZAxis();
    final FrictionSimulation frictionSimulation = FrictionSimulation(
        widget.interactionEndFrictionCoefficient * widget.scaleFactor,
        scale,
        details.scaleVelocity / 10);
    final double tFinal = getFinalTime(
        details.scaleVelocity.abs(), widget.interactionEndFrictionCoefficient,
        effectivelyMotionless: 0.1);
    scaleAnimation =
        Tween<double>(begin: scale, end: frictionSimulation.x(tFinal))
            .animate(CurvedAnimation(
                parent: scaleController, curve: Curves.decelerate));
    scaleController.duration =
        Duration(milliseconds: (tFinal * 1000).round());
    scaleAnimation!.addListener(onScaleAnimate);
    scaleController.forward();
  } else {
    scrollbarController?.onScrollEnd();
  }
}