@@ -14,9 +14,6 @@ OnCropParams caclulateOnCropParams({
14
14
required int imageHeight,
15
15
required CustomImageFit imageFit,
16
16
}) {
17
- /// the size of the ui screen
18
- final double uiSize;
19
-
20
17
/// the size of the area to crop (width and/or height depending on the aspect ratio)
21
18
final double cropSizeMax;
22
19
@@ -28,35 +25,42 @@ OnCropParams caclulateOnCropParams({
28
25
29
26
switch (imageFit) {
30
27
case CustomImageFit .fillCropSpace:
31
- uiSize = min (screenWidth, screenHeight);
32
- cropSizeMax = max (imageWidth, imageHeight).toDouble ();
28
+ final double uiSize;
29
+ if (screenWidth > screenHeight * aspectRatio) {
30
+ uiSize = screenHeight;
31
+ cropSizeMax = imageHeight.toDouble ();
32
+ } else {
33
+ uiSize = screenWidth;
34
+ cropSizeMax = imageWidth.toDouble ();
35
+ }
33
36
translateScale = cropSizeMax / (uiSize * cropPercentage);
34
37
scale = dataScale;
35
38
break ;
36
39
37
40
case CustomImageFit .fitCropSpace:
38
- uiSize = min (screenWidth, screenHeight);
39
- cropSizeMax = max (imageWidth, imageHeight).toDouble ();
41
+ final uiSize = min (screenWidth, screenHeight);
42
+ cropSizeMax = max (imageWidth / min ( 1 , aspectRatio), imageHeight * max ( 1 , aspectRatio) ).toDouble ();
40
43
translateScale = cropSizeMax / (uiSize * cropPercentage);
41
44
scale = dataScale;
42
45
break ;
43
46
44
47
case CustomImageFit .fillCropWidth:
45
- uiSize = screenWidth;
46
- cropSizeMax = imageWidth. toDouble ( );
48
+ final uiSize = screenWidth;
49
+ cropSizeMax = imageWidth / min ( 1 , aspectRatio );
47
50
translateScale = cropSizeMax / (uiSize * cropPercentage);
48
51
scale = dataScale;
49
52
break ;
50
53
51
54
case CustomImageFit .fillCropHeight:
52
- uiSize = screenHeight;
53
- cropSizeMax = imageHeight. toDouble ( );
55
+ final uiSize = screenHeight;
56
+ cropSizeMax = imageHeight * max ( 1 , aspectRatio );
54
57
translateScale = cropSizeMax / (uiSize * cropPercentage);
55
58
scale = dataScale;
56
59
break ;
57
60
58
61
case CustomImageFit .fitVisibleSpace:
59
- if (screenHeight < screenWidth) {
62
+ final double uiSize;
63
+ if (screenHeight * aspectRatio < screenWidth) {
60
64
uiSize = screenHeight;
61
65
cropSizeMax = imageHeight.toDouble ();
62
66
} else {
@@ -70,13 +74,13 @@ OnCropParams caclulateOnCropParams({
70
74
case CustomImageFit .fillVisibleSpace:
71
75
final heightToWidthRatio = (screenHeight / screenWidth);
72
76
73
- if (screenHeight > screenWidth) {
74
- uiSize = screenHeight;
77
+ if (screenHeight * aspectRatio > screenWidth) {
78
+ final uiSize = screenHeight;
75
79
cropSizeMax = imageHeight.toDouble ();
76
80
translateScale = cropSizeMax / uiSize / cropPercentage * heightToWidthRatio;
77
81
scale = dataScale / cropPercentage * heightToWidthRatio;
78
82
} else {
79
- uiSize = screenWidth;
83
+ final uiSize = screenWidth;
80
84
cropSizeMax = imageWidth.toDouble ();
81
85
translateScale = cropSizeMax / uiSize / cropPercentage / heightToWidthRatio;
82
86
scale = dataScale / cropPercentage / heightToWidthRatio;
@@ -85,9 +89,9 @@ OnCropParams caclulateOnCropParams({
85
89
86
90
case CustomImageFit .fillVisibleHeight:
87
91
final heightToWidthRatio = (screenHeight / screenWidth);
88
- uiSize = screenHeight;
92
+ final uiSize = screenHeight;
89
93
cropSizeMax = imageHeight.toDouble ();
90
- if (screenWidth > screenHeight) {
94
+ if (screenWidth > screenHeight * aspectRatio ) {
91
95
translateScale = cropSizeMax / uiSize / cropPercentage;
92
96
scale = dataScale / cropPercentage;
93
97
} else {
@@ -98,9 +102,9 @@ OnCropParams caclulateOnCropParams({
98
102
99
103
case CustomImageFit .fillVisiblelWidth:
100
104
final heightToWidthRatio = (screenHeight / screenWidth);
101
- uiSize = screenWidth;
105
+ final uiSize = screenWidth;
102
106
cropSizeMax = imageWidth.toDouble ();
103
- if (screenWidth > screenHeight) {
107
+ if (screenWidth > screenHeight * aspectRatio ) {
104
108
translateScale = cropSizeMax / uiSize / cropPercentage / heightToWidthRatio;
105
109
scale = dataScale / cropPercentage / heightToWidthRatio;
106
110
} else {
@@ -113,11 +117,11 @@ OnCropParams caclulateOnCropParams({
113
117
final double cropSizeWidth;
114
118
final double cropSizeHeight;
115
119
if (aspectRatio > 1 ) {
116
- cropSizeHeight = cropSizeMax;
117
- cropSizeWidth = cropSizeMax * aspectRatio;
118
- } else {
119
120
cropSizeWidth = cropSizeMax;
120
- cropSizeHeight = cropSizeMax / aspectRatio;
121
+ cropSizeHeight = cropSizeWidth / aspectRatio;
122
+ } else {
123
+ cropSizeHeight = cropSizeMax;
124
+ cropSizeWidth = cropSizeHeight * aspectRatio;
121
125
}
122
126
return OnCropParams (
123
127
cropSizeHeight: cropSizeHeight,
0 commit comments