@@ -76,7 +76,6 @@ class CssBoxWidget extends StatelessWidget {
7676 border: style.border,
7777 color: style.backgroundColor, //Colors the padding and content boxes
7878 ),
79- width: _shouldExpandToFillBlock () ? double .infinity : null ,
8079 padding: padding,
8180 child: top
8281 ? child
@@ -155,13 +154,6 @@ class CssBoxWidget extends StatelessWidget {
155154 return null ;
156155 }
157156
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-
165157 TextDirection _checkTextDirection (
166158 BuildContext context, TextDirection ? direction) {
167159 final textDirection = direction ?? Directionality .maybeOf (context);
@@ -515,7 +507,7 @@ class RenderCSSBox extends RenderBox
515507 RenderBox ? markerBoxChild = parentData.nextSibling;
516508
517509 // Calculate child size
518- final childConstraints = constraints.copyWith (
510+ BoxConstraints childConstraints = constraints.copyWith (
519511 maxWidth: (this .width.unit != Unit .auto)
520512 ? this .width.value
521513 : containingBlockSize.width -
@@ -529,11 +521,25 @@ class RenderCSSBox extends RenderBox
529521 minWidth: (this .width.unit != Unit .auto) ? this .width.value : 0 ,
530522 minHeight: (this .height.unit != Unit .auto) ? this .height.value : 0 ,
531523 );
532- final Size childSize = layoutChild (child, childConstraints);
524+
533525 if (markerBoxChild != null ) {
534526 layoutChild (markerBoxChild, childConstraints);
535527 }
536528
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+
537543 // Calculate used values of margins based on rules
538544 final usedMargins = _calculateUsedMargins (childSize, containingBlockSize);
539545 final horizontalMargins =
@@ -550,7 +556,7 @@ class RenderCSSBox extends RenderBox
550556 width = childSize.width + horizontalMargins;
551557 height = childSize.height + verticalMargins;
552558 } else if (display.isBlock) {
553- width = (shrinkWrap || childIsReplaced)
559+ width = (shrinkWrap || childIsReplaced || containingBlockSize.width.isInfinite )
554560 ? childSize.width + horizontalMargins
555561 : containingBlockSize.width;
556562 height = childSize.height + verticalMargins;
0 commit comments