calcFitToScreen method

  1. @override
dynamic calcFitToScreen({
  1. Curve? curve,
  2. Size? imageSize,
  3. bool animated = true,
})
override

Implementation

@override
calcFitToScreen({
  Curve? curve,
  Size? imageSize,
  bool animated = true,
}) {
  if (!animated) scaleCtrl.duration = Duration.zero;
  Size contentSize = Size(
    editorBodySize.width - _screenPadding * 2,
    editorBodySize.height - _screenPadding * 2,
  );

  double cropSpaceHorizontal =
      _rotated90deg ? _cropSpaceVertical : _cropSpaceHorizontal;
  double cropSpaceVertical =
      _rotated90deg ? _cropSpaceHorizontal : _cropSpaceVertical;

  Size renderedSize = imageSize ?? _renderedImgSize;

  double scaleX =
      contentSize.width / (renderedSize.width - cropSpaceHorizontal);
  double scaleY =
      contentSize.height / (renderedSize.height - cropSpaceVertical);

  double scale = min(scaleX, scaleY);

  scaleAnimation = Tween<double>(begin: oldScaleFactor, end: scale).animate(
    CurvedAnimation(
      parent: scaleCtrl,
      curve: curve ?? cropRotateEditorConfigs.rotateAnimationCurve,
    ),
  );
  scaleCtrl
    ..reset()
    ..forward();

  double startRotateFactor = oldScaleFactor;
  double targetRotateFactor = scale;

  oldScaleFactor = scale;

  cropPainterKey.currentState?.setForegroundPainter(cropPainter);

  if (!startRotateFactor.isInfinite &&
      !startRotateFactor.isNaN &&
      !targetRotateFactor.isInfinite &&
      !targetRotateFactor.isNaN) {
    loopWithTransitionTiming(
      (double curveT) {
        _rotationScaleFactor =
            lerpDouble(startRotateFactor, targetRotateFactor, curveT)!;
        cropPainterKey.currentState?.setForegroundPainter(cropPainter);
      },
      mounted: mounted,
      duration: cropRotateEditorConfigs.animationDuration,
      transitionFunction:
          (curve ?? cropRotateEditorConfigs.rotateAnimationCurve).transform,
    );
  } else {
    _rotationScaleFactor = 1;
  }

  if (!animated) {
    scaleCtrl.duration = cropRotateEditorConfigs.animationDuration;
  }
}