@@ -76,7 +76,6 @@ class CssBoxWidget extends StatelessWidget {
76
76
border: style.border,
77
77
color: style.backgroundColor, //Colors the padding and content boxes
78
78
),
79
- width: _shouldExpandToFillBlock () ? double .infinity : null ,
80
79
padding: padding,
81
80
child: top
82
81
? child
@@ -155,13 +154,6 @@ class CssBoxWidget extends StatelessWidget {
155
154
return null ;
156
155
}
157
156
158
- /// Whether or not the content-box should expand its width to fill the
159
- /// width available to it or if it should just let its inner content
160
- /// determine the content-box's width.
161
- bool _shouldExpandToFillBlock () {
162
- return (style.display? .isBlock ?? false ) && ! childIsReplaced && ! shrinkWrap;
163
- }
164
-
165
157
TextDirection _checkTextDirection (
166
158
BuildContext context, TextDirection ? direction) {
167
159
final textDirection = direction ?? Directionality .maybeOf (context);
@@ -515,7 +507,7 @@ class RenderCSSBox extends RenderBox
515
507
RenderBox ? markerBoxChild = parentData.nextSibling;
516
508
517
509
// Calculate child size
518
- final childConstraints = constraints.copyWith (
510
+ BoxConstraints childConstraints = constraints.copyWith (
519
511
maxWidth: (this .width.unit != Unit .auto)
520
512
? this .width.value
521
513
: containingBlockSize.width -
@@ -529,11 +521,25 @@ class RenderCSSBox extends RenderBox
529
521
minWidth: (this .width.unit != Unit .auto) ? this .width.value : 0 ,
530
522
minHeight: (this .height.unit != Unit .auto) ? this .height.value : 0 ,
531
523
);
532
- final Size childSize = layoutChild (child, childConstraints);
524
+
533
525
if (markerBoxChild != null ) {
534
526
layoutChild (markerBoxChild, childConstraints);
535
527
}
536
528
529
+ // If this element is a block element and not otherwise constrained,
530
+ // we constrain the child Container to fill the entire width of this
531
+ // Widget's parent, if possible. This is equivalent to setting
532
+ // `width: double.infinity` on the inner Container, but we do it here
533
+ // to keep the infinite width from being applied if the parent's width is
534
+ // also infinite.
535
+ if (display.isBlock && ! shrinkWrap && ! childIsReplaced && containingBlockSize.width.isFinite) {
536
+ childConstraints = childConstraints.enforce (BoxConstraints (
537
+ maxWidth: math.max (containingBlockSize.width, childConstraints.maxWidth),
538
+ minWidth: childConstraints.maxWidth,
539
+ ));
540
+ }
541
+ final Size childSize = layoutChild (child, childConstraints);
542
+
537
543
// Calculate used values of margins based on rules
538
544
final usedMargins = _calculateUsedMargins (childSize, containingBlockSize);
539
545
final horizontalMargins =
@@ -550,7 +556,7 @@ class RenderCSSBox extends RenderBox
550
556
width = childSize.width + horizontalMargins;
551
557
height = childSize.height + verticalMargins;
552
558
} else if (display.isBlock) {
553
- width = (shrinkWrap || childIsReplaced)
559
+ width = (shrinkWrap || childIsReplaced || containingBlockSize.width.isInfinite )
554
560
? childSize.width + horizontalMargins
555
561
: containingBlockSize.width;
556
562
height = childSize.height + verticalMargins;
0 commit comments