@@ -13,6 +13,53 @@ final class ScaleResizer extends Resizer {
1313 required HandlePosition handle,
1414 required Constraints constraints,
1515 required Flip flip,
16+ }) {
17+ ({Box rect, Box largest, bool hasValidFlip}) result = _resizeRect (
18+ initialRect: initialRect,
19+ explodedRect: explodedRect,
20+ clampingRect: clampingRect,
21+ handle: handle,
22+ constraints: constraints,
23+ flip: flip,
24+ );
25+
26+ if (! result.hasValidFlip) {
27+ // Since we can't flip the box, explodedRect (which is a raw rect with delta applied)
28+ // would be flipped so we can't use that because it would make the size
29+ // calculations wrong. Instead we use box from the result which is the
30+ // flipped box but with correct constraints applied. (min rect always).
31+ final newResult = _resizeRect (
32+ explodedRect: result.rect,
33+ initialRect: initialRect,
34+ clampingRect: clampingRect,
35+ handle: handle,
36+ flip: Flip .none,
37+ constraints: constraints,
38+ );
39+
40+ if (! newResult.hasValidFlip) {
41+ // This should never happen. If it does, it means that the box is
42+ // invalid even after flipping it back to the original state and we
43+ // can't flip it back again. This means that the box might be invalid
44+ // in the first place or something catastrophic happened!!! Contact
45+ // the package author if this happens.
46+ return (rect: initialRect,largest: clampingRect, hasValidFlip: false );
47+ throw StateError ('Box found to be invalid more than once!' );
48+ }
49+
50+ return newResult;
51+ }
52+
53+ return result;
54+ }
55+
56+ ({Box rect, Box largest, bool hasValidFlip}) _resizeRect ({
57+ required Box initialRect,
58+ required Box explodedRect,
59+ required Box clampingRect,
60+ required HandlePosition handle,
61+ required Constraints constraints,
62+ required Flip flip,
1663 }) {
1764 final flippedHandle = handle.flip (flip);
1865 final effectiveInitialRect = flipRect (initialRect, flip, handle);
@@ -56,21 +103,6 @@ final class ScaleResizer extends Resizer {
56103 break ;
57104 }
58105
59- if (! result.hasValidFlip) {
60- // Since we can't flip the box, explodedRect (which is a raw rect with delta applied)
61- // would be flipped so we can't use that because it would make the size
62- // calculations wrong. Instead we use box from the result which is the
63- // flipped box but with correct constraints applied. (min rect always).
64- return resize (
65- explodedRect: result.rect,
66- initialRect: initialRect,
67- clampingRect: clampingRect,
68- handle: handle,
69- flip: Flip .none,
70- constraints: constraints,
71- );
72- }
73-
74106 return result;
75107 }
76108
0 commit comments