@@ -128,6 +128,7 @@ class BoxTransformer {
128128 constraints: constraints,
129129 allowResizeOverflow: allowResizeOverflow,
130130 localPosition: localPosition,
131+ flipRect: flipRect,
131132 );
132133
133134 final Box newRect = result.rect;
@@ -190,6 +191,7 @@ class BoxTransformer {
190191 required HandlePosition handle,
191192 required Vector2 delta,
192193 required ResizeMode resizeMode,
194+ required bool flipRect,
193195 }) {
194196 double left;
195197 double top;
@@ -201,18 +203,40 @@ class BoxTransformer {
201203 right = initialBox.right + (handle.influencesRight ? delta.x : 0 );
202204 bottom = initialBox.bottom + (handle.influencesBottom ? delta.y : 0 );
203205
204- final double width = (right - left).abs ();
205- final double height = (bottom - top).abs ();
206+ double width = right - left;
207+ double height = bottom - top;
208+
209+ if (flipRect) {
210+ width = width.abs ();
211+ height = height.abs ();
212+ } else {
213+ // If not flipping, we need to make sure the width and height are
214+ // positive which would imply that the left and top are less than
215+ // the right and bottom respectively stopping rect from flipping.
216+ width = width.clamp (0 , double .infinity);
217+ height = height.clamp (0 , double .infinity);
218+ }
206219
207220 // If in symmetric scaling mode, utilize width and height to constructor
208221 // the new box from its center.
209222 if (resizeMode.hasSymmetry) {
223+ // symmetric resizing is not affected if flipping is disabled.
210224 final widthDelta = (initialBox.width - width) / 2 ;
211225 final heightDelta = (initialBox.height - height) / 2 ;
212226 left = initialBox.left + widthDelta;
213227 top = initialBox.top + heightDelta;
214228 right = initialBox.right - widthDelta;
215229 bottom = initialBox.bottom - heightDelta;
230+ } else if (! flipRect) {
231+ // If not flipping, then we know that handles are not allowed to
232+ // cross the opposite one. So we use handle with width and height
233+ // instead of left, top, right, bottom to construct the new box.
234+ return Box .fromHandle (
235+ handle.anchor (initialBox),
236+ handle,
237+ width,
238+ height,
239+ );
216240 }
217241
218242 return Box .fromLTRB (
@@ -233,6 +257,7 @@ class BoxTransformer {
233257 Constraints constraints = const Constraints .unconstrained (),
234258 bool allowResizeOverflow = true ,
235259 required Vector2 localPosition,
260+ required bool flipRect,
236261 }) {
237262 // No constraints or clamping is done. Only delta is applied to the
238263 // initial box.
@@ -241,6 +266,7 @@ class BoxTransformer {
241266 handle: handle,
242267 delta: delta,
243268 resizeMode: resizeMode,
269+ flipRect: flipRect,
244270 );
245271
246272 InternalResizeResult result;
@@ -315,7 +341,7 @@ class BoxTransformer {
315341 //
316342 // final double newWidth;
317343 // final double newHeight;
318- // final newAspectRatio = rect.width / rect.height ;
344+ // final newAspectRatio = rect.safeAspectRatio ;
319345 //
320346 // if (resizeMode.isScalable) {
321347 // if (newAspectRatio.abs() < aspectRatio.abs()) {
@@ -422,14 +448,14 @@ class BoxTransformer {
422448 constraints: constraints,
423449 );
424450
425- final initialAspectRatio = initialRect.width / initialRect.height ;
451+ final initialAspectRatio = initialRect.safeAspectRatio ;
426452
427453 double rectWidth = rect.width;
428454 double rectHeight = rect.height;
429455
430456 final cursorRect = rect;
431457
432- if (cursorRect.aspectRatio .abs () < initialAspectRatio.abs ()) {
458+ if (cursorRect.safeAspectRatio .abs () < initialAspectRatio.abs ()) {
433459 rectWidth = rectHeight * initialAspectRatio;
434460 } else {
435461 rectHeight = rectWidth / initialAspectRatio;
@@ -478,7 +504,7 @@ class BoxTransformer {
478504 Constraints constraints,
479505 Flip flip,
480506 ) {
481- final initialAspectRatio = initialRect.width / initialRect.height ;
507+ final initialAspectRatio = initialRect.safeAspectRatio ;
482508
483509 Box area = getAvailableAreaForHandle (
484510 rect: initialRect,
@@ -555,7 +581,7 @@ class BoxTransformer {
555581 Constraints constraints,
556582 Flip flip,
557583 ) {
558- final initialAspectRatio = initialRect.width / initialRect.height ;
584+ final initialAspectRatio = initialRect.safeAspectRatio ;
559585
560586 Box area = getAvailableAreaForHandle (
561587 rect: initialRect,
@@ -632,7 +658,7 @@ class BoxTransformer {
632658 Constraints constraints,
633659 Flip flip,
634660 ) {
635- final initialAspectRatio = initialRect.width / initialRect.height ;
661+ final initialAspectRatio = initialRect.safeAspectRatio ;
636662
637663 Box area = getAvailableAreaForHandle (
638664 rect: initialRect,
@@ -709,7 +735,7 @@ class BoxTransformer {
709735 Constraints constraints,
710736 Flip flip,
711737 ) {
712- final initialAspectRatio = initialRect.width / initialRect.height ;
738+ final initialAspectRatio = initialRect.safeAspectRatio ;
713739
714740 Box area = getAvailableAreaForHandle (
715741 rect: initialRect,
@@ -785,7 +811,7 @@ class BoxTransformer {
785811 HandlePosition handle,
786812 Constraints constraints,
787813 ) {
788- final initialAspectRatio = initialRect.width / initialRect.height ;
814+ final initialAspectRatio = initialRect.safeAspectRatio ;
789815
790816 final Box availableArea;
791817
@@ -811,7 +837,7 @@ class BoxTransformer {
811837 if (! constraints.isUnconstrained) {
812838 final double minWidth;
813839 final double minHeight;
814- if (initialRect.aspectRatio > 1 ) {
840+ if (initialRect.safeAspectRatio > 1 ) {
815841 minHeight = constraints.minHeight;
816842 minWidth = minHeight * initialAspectRatio;
817843 } else {
@@ -836,7 +862,7 @@ class BoxTransformer {
836862
837863 final cursorRect = rect;
838864
839- if (cursorRect.aspectRatio .abs () < initialAspectRatio.abs ()) {
865+ if (cursorRect.safeAspectRatio .abs () < initialAspectRatio.abs ()) {
840866 rectWidth = rectHeight * initialAspectRatio;
841867 } else {
842868 rectHeight = rectWidth / initialAspectRatio;
@@ -866,7 +892,7 @@ class BoxTransformer {
866892 HandlePosition handle,
867893 Constraints constraints,
868894 ) {
869- final initialAspectRatio = initialRect.width / initialRect.height ;
895+ final initialAspectRatio = initialRect.safeAspectRatio ;
870896
871897 final Box availableArea;
872898
@@ -892,7 +918,7 @@ class BoxTransformer {
892918 if (! constraints.isUnconstrained) {
893919 final double minWidth;
894920 final double minHeight;
895- if (initialRect.aspectRatio > 1 ) {
921+ if (initialRect.safeAspectRatio > 1 ) {
896922 minHeight = constraints.minHeight;
897923 minWidth = minHeight * initialAspectRatio;
898924 } else {
@@ -961,14 +987,14 @@ class BoxTransformer {
961987 constraints: constraints,
962988 );
963989
964- final initialAspectRatio = initialRect.width / initialRect.height ;
990+ final initialAspectRatio = initialRect.safeAspectRatio ;
965991
966992 double rectWidth = rect.width;
967993 double rectHeight = rect.height;
968994
969995 final cursorRect = rect;
970996
971- if (cursorRect.aspectRatio .abs () < initialAspectRatio.abs ()) {
997+ if (cursorRect.safeAspectRatio .abs () < initialAspectRatio.abs ()) {
972998 rectWidth = rectHeight * initialAspectRatio;
973999 } else {
9741000 rectHeight = rectWidth / initialAspectRatio;
@@ -1032,14 +1058,14 @@ class BoxTransformer {
10321058 constraints: constraints,
10331059 );
10341060
1035- final initialAspectRatio = initialRect.width / initialRect.height ;
1061+ final initialAspectRatio = initialRect.safeAspectRatio ;
10361062
10371063 double rectWidth = rect.width;
10381064 double rectHeight = rect.height;
10391065
10401066 final cursorRect = rect;
10411067
1042- if (cursorRect.aspectRatio .abs () < initialAspectRatio.abs ()) {
1068+ if (cursorRect.safeAspectRatio .abs () < initialAspectRatio.abs ()) {
10431069 rectWidth = rectHeight * initialAspectRatio;
10441070 } else {
10451071 rectHeight = rectWidth / initialAspectRatio;
@@ -1103,14 +1129,14 @@ class BoxTransformer {
11031129 constraints: constraints,
11041130 );
11051131
1106- final initialAspectRatio = initialRect.width / initialRect.height ;
1132+ final initialAspectRatio = initialRect.safeAspectRatio ;
11071133
11081134 double rectWidth = rect.width;
11091135 double rectHeight = rect.height;
11101136
11111137 final cursorRect = rect;
11121138
1113- if (cursorRect.aspectRatio .abs () < initialAspectRatio.abs ()) {
1139+ if (cursorRect.safeAspectRatio .abs () < initialAspectRatio.abs ()) {
11141140 rectWidth = rectHeight * initialAspectRatio;
11151141 } else {
11161142 rectHeight = rectWidth / initialAspectRatio;
0 commit comments