calcCropRect method

  1. @override
void calcCropRect({
  1. bool onlyViewRect = false,
  2. double? newRatio,
})
override

Implementation

@override
void calcCropRect({bool onlyViewRect = false, double? newRatio}) {
  double imgSizeRatio = _imgHeight / _imgWidth;

  var imgConstraints = _renderedImgConstraints.biggest.isInfinite
      ? imageInfos?.renderedSize ?? _renderedImgConstraints.biggest
      : _renderedImgConstraints.biggest;

  double imgW = imgConstraints.width;
  double imgH = imgConstraints.height;

  double realImgW = imageSticksToScreenWidth ? imgW : imgH / imgSizeRatio;
  double realImgH = imageSticksToScreenWidth ? imgW * imgSizeRatio : imgH;

  // Rect stick horizontal
  double ratio = newRatio ?? (_ratio > 0 ? _ratio : imgSizeRatio);
  double left = 0;
  double top = 0;

  if (imgSizeRatio >= ratio) {
    double newH = realImgW * ratio;
    top = (realImgH - newH) / 2;
    realImgH = newH;
  }
  // Rect stick vertical
  else {
    double newW = realImgH / ratio;
    left = (realImgW - newW) / 2;
    realImgW = newW;
  }

  _cropSpaceVertical = top * 2;
  _cropSpaceHorizontal = left * 2;

  if (!onlyViewRect) {
    cropRect = Rect.fromLTWH(left, top, realImgW, realImgH);
  }
  _viewRect = Rect.fromLTWH(left, top, realImgW, realImgH);
  cropPainterKey.currentState?.setForegroundPainter(cropPainter);
}