@@ -23,9 +23,11 @@ OnCropParams caclulateOnCropParams({
23
23
/// used to adjust image scale
24
24
final double scale;
25
25
26
+ /// Temp variable used to calculate the translateScale
27
+ final double uiSize;
28
+
26
29
switch (imageFit) {
27
30
case CustomImageFit .fillCropSpace:
28
- final double uiSize;
29
31
if (screenWidth > screenHeight * aspectRatio) {
30
32
uiSize = screenHeight;
31
33
cropSizeMax = imageHeight.toDouble ();
@@ -38,21 +40,26 @@ OnCropParams caclulateOnCropParams({
38
40
break ;
39
41
40
42
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
+ }
43
50
translateScale = cropSizeMax / (uiSize * cropPercentage);
44
51
scale = dataScale;
45
52
break ;
46
53
47
54
case CustomImageFit .fillCropWidth:
48
- final uiSize = screenWidth;
55
+ uiSize = screenWidth;
49
56
cropSizeMax = imageWidth / min (1 , aspectRatio);
50
57
translateScale = cropSizeMax / (uiSize * cropPercentage);
51
58
scale = dataScale;
52
59
break ;
53
60
54
61
case CustomImageFit .fillCropHeight:
55
- final uiSize = screenHeight;
62
+ uiSize = screenHeight;
56
63
cropSizeMax = imageHeight * max (1 , aspectRatio);
57
64
translateScale = cropSizeMax / (uiSize * cropPercentage);
58
65
scale = dataScale;
@@ -75,12 +82,12 @@ OnCropParams caclulateOnCropParams({
75
82
final heightToWidthRatio = (screenHeight / screenWidth);
76
83
77
84
if (screenHeight * aspectRatio > screenWidth) {
78
- final uiSize = screenHeight;
85
+ uiSize = screenHeight;
79
86
cropSizeMax = imageHeight.toDouble ();
80
87
translateScale = cropSizeMax / uiSize / cropPercentage * heightToWidthRatio;
81
88
scale = dataScale / cropPercentage * heightToWidthRatio;
82
89
} else {
83
- final uiSize = screenWidth;
90
+ uiSize = screenWidth;
84
91
cropSizeMax = imageWidth.toDouble ();
85
92
translateScale = cropSizeMax / uiSize / cropPercentage / heightToWidthRatio;
86
93
scale = dataScale / cropPercentage / heightToWidthRatio;
@@ -89,7 +96,7 @@ OnCropParams caclulateOnCropParams({
89
96
90
97
case CustomImageFit .fillVisibleHeight:
91
98
final heightToWidthRatio = (screenHeight / screenWidth);
92
- final uiSize = screenHeight;
99
+ uiSize = screenHeight;
93
100
cropSizeMax = imageHeight.toDouble ();
94
101
if (screenWidth > screenHeight * aspectRatio) {
95
102
translateScale = cropSizeMax / uiSize / cropPercentage;
@@ -102,7 +109,7 @@ OnCropParams caclulateOnCropParams({
102
109
103
110
case CustomImageFit .fillVisiblelWidth:
104
111
final heightToWidthRatio = (screenHeight / screenWidth);
105
- final uiSize = screenWidth;
112
+ uiSize = screenWidth;
106
113
cropSizeMax = imageWidth.toDouble ();
107
114
if (screenWidth > screenHeight * aspectRatio) {
108
115
translateScale = cropSizeMax / uiSize / cropPercentage / heightToWidthRatio;
0 commit comments