Skip to content

Commit 16541ba

Browse files
Fixed based op crop size
1 parent 82eca2c commit 16541ba

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lib/src/calculators/calculate_on_crop_params.dart

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ OnCropParams caclulateOnCropParams({
2323
/// used to adjust image scale
2424
final double scale;
2525

26+
/// Temp variable used to calculate the translateScale
27+
final double uiSize;
28+
2629
switch (imageFit) {
2730
case CustomImageFit.fillCropSpace:
28-
final double uiSize;
2931
if (screenWidth > screenHeight * aspectRatio) {
3032
uiSize = screenHeight;
3133
cropSizeMax = imageHeight.toDouble();
@@ -38,21 +40,26 @@ OnCropParams caclulateOnCropParams({
3840
break;
3941

4042
case CustomImageFit.fitCropSpace:
41-
final uiSize = min(screenWidth, screenHeight);
42-
cropSizeMax = max(imageWidth / min(1, aspectRatio), imageHeight * max(1, aspectRatio)).toDouble();
43+
if (screenWidth > screenHeight * aspectRatio) {
44+
uiSize = screenHeight;
45+
cropSizeMax = imageWidth.toDouble() / aspectRatio;
46+
} else {
47+
uiSize = screenWidth;
48+
cropSizeMax = imageHeight.toDouble() * aspectRatio;
49+
}
4350
translateScale = cropSizeMax / (uiSize * cropPercentage);
4451
scale = dataScale;
4552
break;
4653

4754
case CustomImageFit.fillCropWidth:
48-
final uiSize = screenWidth;
55+
uiSize = screenWidth;
4956
cropSizeMax = imageWidth / min(1, aspectRatio);
5057
translateScale = cropSizeMax / (uiSize * cropPercentage);
5158
scale = dataScale;
5259
break;
5360

5461
case CustomImageFit.fillCropHeight:
55-
final uiSize = screenHeight;
62+
uiSize = screenHeight;
5663
cropSizeMax = imageHeight * max(1, aspectRatio);
5764
translateScale = cropSizeMax / (uiSize * cropPercentage);
5865
scale = dataScale;
@@ -75,12 +82,12 @@ OnCropParams caclulateOnCropParams({
7582
final heightToWidthRatio = (screenHeight / screenWidth);
7683

7784
if (screenHeight * aspectRatio > screenWidth) {
78-
final uiSize = screenHeight;
85+
uiSize = screenHeight;
7986
cropSizeMax = imageHeight.toDouble();
8087
translateScale = cropSizeMax / uiSize / cropPercentage * heightToWidthRatio;
8188
scale = dataScale / cropPercentage * heightToWidthRatio;
8289
} else {
83-
final uiSize = screenWidth;
90+
uiSize = screenWidth;
8491
cropSizeMax = imageWidth.toDouble();
8592
translateScale = cropSizeMax / uiSize / cropPercentage / heightToWidthRatio;
8693
scale = dataScale / cropPercentage / heightToWidthRatio;
@@ -89,7 +96,7 @@ OnCropParams caclulateOnCropParams({
8996

9097
case CustomImageFit.fillVisibleHeight:
9198
final heightToWidthRatio = (screenHeight / screenWidth);
92-
final uiSize = screenHeight;
99+
uiSize = screenHeight;
93100
cropSizeMax = imageHeight.toDouble();
94101
if (screenWidth > screenHeight * aspectRatio) {
95102
translateScale = cropSizeMax / uiSize / cropPercentage;
@@ -102,7 +109,7 @@ OnCropParams caclulateOnCropParams({
102109

103110
case CustomImageFit.fillVisiblelWidth:
104111
final heightToWidthRatio = (screenHeight / screenWidth);
105-
final uiSize = screenWidth;
112+
uiSize = screenWidth;
106113
cropSizeMax = imageWidth.toDouble();
107114
if (screenWidth > screenHeight * aspectRatio) {
108115
translateScale = cropSizeMax / uiSize / cropPercentage / heightToWidthRatio;

0 commit comments

Comments
 (0)