@@ -175,6 +175,10 @@ extension WidgetsExt on Widget {
175
175
OnLayoutCallback ? callback,
176
176
double chainWeight = 1 ,
177
177
bool percentageTranslate = false ,
178
+ double minWidth = 0 ,
179
+ double maxWidth = matchParent,
180
+ double minHeight = 0 ,
181
+ double maxHeight = matchParent,
178
182
}) {
179
183
return Constrained (
180
184
key: key,
@@ -216,6 +220,10 @@ extension WidgetsExt on Widget {
216
220
callback: callback,
217
221
chainWeight: chainWeight,
218
222
percentageTranslate: percentageTranslate,
223
+ minWidth: minWidth,
224
+ maxWidth: maxWidth,
225
+ minHeight: minHeight,
226
+ maxHeight: maxHeight,
219
227
),
220
228
child: this ,
221
229
);
@@ -449,6 +457,14 @@ class Constraint {
449
457
final double chainWeight;
450
458
final bool percentageTranslate;
451
459
460
+ /// Only takes effect when width is wrapContent
461
+ final double minWidth;
462
+ final double maxWidth;
463
+
464
+ /// Only takes effect when height is wrapContent
465
+ final double minHeight;
466
+ final double maxHeight;
467
+
452
468
Constraint ({
453
469
this .id,
454
470
this .width = wrapContent,
@@ -487,6 +503,10 @@ class Constraint {
487
503
this .callback,
488
504
this .chainWeight = 1 ,
489
505
this .percentageTranslate = false ,
506
+ this .minWidth = 0 ,
507
+ this .maxWidth = matchParent,
508
+ this .minHeight = 0 ,
509
+ this .maxHeight = matchParent,
490
510
});
491
511
492
512
@override
@@ -529,7 +549,11 @@ class Constraint {
529
549
centerHorizontalTo == other.centerHorizontalTo &&
530
550
centerVerticalTo == other.centerVerticalTo &&
531
551
callback == other.callback &&
532
- percentageTranslate == other.percentageTranslate;
552
+ percentageTranslate == other.percentageTranslate &&
553
+ minWidth == other.minWidth &&
554
+ maxWidth == other.maxWidth &&
555
+ minHeight == other.minHeight &&
556
+ maxHeight == other.maxHeight;
533
557
534
558
@override
535
559
int get hashCode =>
@@ -568,7 +592,11 @@ class Constraint {
568
592
centerHorizontalTo.hashCode ^
569
593
centerVerticalTo.hashCode ^
570
594
callback.hashCode ^
571
- percentageTranslate.hashCode;
595
+ percentageTranslate.hashCode ^
596
+ minWidth.hashCode ^
597
+ maxWidth.hashCode ^
598
+ minHeight.hashCode ^
599
+ maxHeight.hashCode;
572
600
573
601
bool checkSize (double size) {
574
602
if (size == matchParent || size == wrapContent || size == matchConstraint) {
@@ -621,6 +649,10 @@ class Constraint {
621
649
_debugEnsureNegativePercent ('xTranslate' , translate.dx));
622
650
assert (! percentageTranslate ||
623
651
_debugEnsureNegativePercent ('yTranslate' , translate.dy));
652
+ assert (minWidth >= 0 );
653
+ assert (maxWidth == matchParent || maxWidth >= minWidth);
654
+ assert (minHeight >= 0 );
655
+ assert (maxHeight == matchParent || maxHeight >= minHeight);
624
656
return true ;
625
657
}
626
658
@@ -856,6 +888,26 @@ class Constraint {
856
888
needsPaint = true ;
857
889
}
858
890
891
+ if (parentData.minWidth != minWidth) {
892
+ parentData.minWidth = minWidth;
893
+ needsLayout = true ;
894
+ }
895
+
896
+ if (parentData.maxWidth != maxWidth) {
897
+ parentData.maxWidth = maxWidth;
898
+ needsLayout = true ;
899
+ }
900
+
901
+ if (parentData.minHeight != minHeight) {
902
+ parentData.minHeight = minHeight;
903
+ needsLayout = true ;
904
+ }
905
+
906
+ if (parentData.maxHeight != maxHeight) {
907
+ parentData.maxHeight = maxHeight;
908
+ needsLayout = true ;
909
+ }
910
+
859
911
if (needsLayout) {
860
912
AbstractNode ? targetParent = renderObject.parent;
861
913
if (targetParent is RenderObject ) {
@@ -912,6 +964,10 @@ class _ConstraintBoxData extends ContainerBoxParentData<RenderBox> {
912
964
double ? verticalBias;
913
965
OnLayoutCallback ? callback;
914
966
bool ? percentageTranslate;
967
+ double ? minWidth;
968
+ double ? maxWidth;
969
+ double ? minHeight;
970
+ double ? maxHeight;
915
971
916
972
// for internal use
917
973
late Map <ConstraintId , _ConstrainedNode > _tempConstrainedNodes;
@@ -1440,19 +1496,24 @@ class _ConstraintRenderBox extends RenderBox
1440
1496
EdgeInsets goneMargin = element.goneMargin;
1441
1497
1442
1498
/// Calculate child width
1443
- double minWidth = 0 ;
1444
- double maxWidth = double .infinity ;
1445
- double minHeight = 0 ;
1446
- double maxHeight = double .infinity ;
1499
+ double minWidth;
1500
+ double maxWidth;
1501
+ double minHeight;
1502
+ double maxHeight;
1447
1503
if (element.visibility == gone) {
1448
1504
minWidth = 0 ;
1449
1505
maxWidth = 0 ;
1450
- minWidth = 0 ;
1506
+ minHeight = 0 ;
1451
1507
maxHeight = 0 ;
1452
1508
} else {
1453
1509
double width = element.width;
1454
1510
if (width == wrapContent) {
1455
- maxWidth = size.width;
1511
+ minWidth = element.minWidth;
1512
+ if (element.maxWidth == matchParent) {
1513
+ maxWidth = size.width;
1514
+ } else {
1515
+ maxWidth = element.maxWidth;
1516
+ }
1456
1517
} else if (width == matchParent) {
1457
1518
minWidth = size.width -
1458
1519
_getHorizontalInsets (
@@ -1523,7 +1584,12 @@ class _ConstraintRenderBox extends RenderBox
1523
1584
/// Calculate child height
1524
1585
double height = element.height;
1525
1586
if (height == wrapContent) {
1526
- maxHeight = size.height;
1587
+ minHeight = element.minHeight;
1588
+ if (element.maxHeight == matchParent) {
1589
+ maxHeight = size.height;
1590
+ } else {
1591
+ maxHeight = element.maxHeight;
1592
+ }
1527
1593
} else if (height == matchParent) {
1528
1594
minHeight = size.height -
1529
1595
_getVerticalInsets (margin, element.percentageMargin, size.height);
@@ -2165,6 +2231,14 @@ class _ConstrainedNode {
2165
2231
2166
2232
bool get percentageMargin => parentData.percentageMargin! ;
2167
2233
2234
+ double get minWidth => parentData.minWidth! ;
2235
+
2236
+ double get maxWidth => parentData.maxWidth! ;
2237
+
2238
+ double get minHeight => parentData.minHeight! ;
2239
+
2240
+ double get maxHeight => parentData.maxHeight! ;
2241
+
2168
2242
PercentageAnchor get widthPercentageAnchor =>
2169
2243
parentData.widthPercentageAnchor! ;
2170
2244
@@ -2402,6 +2476,10 @@ class _InternalBox extends RenderBox {
2402
2476
constraintBoxData._direction = null ;
2403
2477
constraintBoxData._referencedIds = null ;
2404
2478
constraintBoxData.percentageTranslate = false ;
2479
+ constraintBoxData.minWidth = 0 ;
2480
+ constraintBoxData.maxWidth = double .infinity;
2481
+ constraintBoxData.minHeight = 0 ;
2482
+ constraintBoxData.maxHeight = double .infinity;
2405
2483
}
2406
2484
}
2407
2485
0 commit comments