@@ -159,10 +159,7 @@ class CssBoxWidget extends StatelessWidget {
159
159
/// width available to it or if it should just let its inner content
160
160
/// determine the content-box's width.
161
161
bool _shouldExpandToFillBlock () {
162
- return (style.display == Display .block ||
163
- style.display == Display .listItem) &&
164
- ! childIsReplaced &&
165
- ! shrinkWrap;
162
+ return (style.display? .isBlock ?? false ) && ! childIsReplaced && ! shrinkWrap;
166
163
}
167
164
168
165
TextDirection _checkTextDirection (
@@ -424,42 +421,62 @@ class RenderCSSBox extends RenderBox
424
421
}
425
422
}
426
423
427
- static double getIntrinsicDimension (RenderBox ? firstChild,
428
- double Function (RenderBox child) mainChildSizeGetter) {
424
+ static double getIntrinsicDimension (
425
+ RenderBox ? firstChild,
426
+ double Function (RenderBox child) mainChildSizeGetter,
427
+ double marginSpaceNeeded) {
429
428
double extent = 0.0 ;
430
429
RenderBox ? child = firstChild;
431
430
while (child != null ) {
432
431
final CSSBoxParentData childParentData =
433
432
child.parentData! as CSSBoxParentData ;
434
- extent = math.max (extent, mainChildSizeGetter (child));
433
+ try {
434
+ extent = math.max (extent, mainChildSizeGetter (child));
435
+ } catch (_) {
436
+ // See https://github.com/flutter/flutter/issues/65895
437
+ debugPrint (
438
+ "Due to Flutter layout restrictions (see https://github.com/flutter/flutter/issues/65895), contents set to `vertical-align: baseline` within an intrinsically-sized layout may not display as expected. If content is cut off or displaying incorrectly, please try setting vertical-align to 'bottom' on the problematic elements" );
439
+ }
435
440
assert (child.parentData == childParentData);
436
441
child = childParentData.nextSibling;
437
442
}
438
- return extent;
443
+ return extent + marginSpaceNeeded ;
439
444
}
440
445
441
446
@override
442
447
double computeMinIntrinsicWidth (double height) {
443
448
return getIntrinsicDimension (
444
- firstChild, (RenderBox child) => child.getMinIntrinsicWidth (height));
449
+ firstChild,
450
+ (RenderBox child) => child.getMinIntrinsicWidth (height),
451
+ _calculateIntrinsicMargins ().horizontal,
452
+ );
445
453
}
446
454
447
455
@override
448
456
double computeMaxIntrinsicWidth (double height) {
449
457
return getIntrinsicDimension (
450
- firstChild, (RenderBox child) => child.getMaxIntrinsicWidth (height));
458
+ firstChild,
459
+ (RenderBox child) => child.getMaxIntrinsicWidth (height),
460
+ _calculateIntrinsicMargins ().horizontal,
461
+ );
451
462
}
452
463
453
464
@override
454
465
double computeMinIntrinsicHeight (double width) {
455
466
return getIntrinsicDimension (
456
- firstChild, (RenderBox child) => child.getMinIntrinsicHeight (width));
467
+ firstChild,
468
+ (RenderBox child) => child.getMinIntrinsicHeight (width),
469
+ _calculateIntrinsicMargins ().vertical,
470
+ );
457
471
}
458
472
459
473
@override
460
474
double computeMaxIntrinsicHeight (double width) {
461
475
return getIntrinsicDimension (
462
- firstChild, (RenderBox child) => child.getMaxIntrinsicHeight (width));
476
+ firstChild,
477
+ (RenderBox child) => child.getMaxIntrinsicHeight (width),
478
+ _calculateIntrinsicMargins ().vertical,
479
+ );
463
480
}
464
481
465
482
@override
@@ -521,31 +538,20 @@ class RenderCSSBox extends RenderBox
521
538
522
539
//Calculate Width and Height of CSS Box
523
540
height = childSize.height;
524
- switch (display) {
525
- case Display .block:
526
- width = (shrinkWrap || childIsReplaced)
527
- ? childSize.width + horizontalMargins
528
- : containingBlockSize.width;
529
- height = childSize.height + verticalMargins;
530
- break ;
531
- case Display .inline:
532
- width = childSize.width + horizontalMargins;
533
- height = childSize.height;
534
- break ;
535
- case Display .inlineBlock:
536
- width = childSize.width + horizontalMargins;
537
- height = childSize.height + verticalMargins;
538
- break ;
539
- case Display .listItem:
540
- width = shrinkWrap
541
- ? childSize.width + horizontalMargins
542
- : containingBlockSize.width;
543
- height = childSize.height + verticalMargins;
544
- break ;
545
- case Display .none:
546
- width = 0 ;
547
- height = 0 ;
548
- break ;
541
+ if (display.displayBox == DisplayBox .none) {
542
+ width = 0 ;
543
+ height = 0 ;
544
+ } else if (display == Display .inlineBlock) {
545
+ width = childSize.width + horizontalMargins;
546
+ height = childSize.height + verticalMargins;
547
+ } else if (display.isBlock) {
548
+ width = (shrinkWrap || childIsReplaced)
549
+ ? childSize.width + horizontalMargins
550
+ : containingBlockSize.width;
551
+ height = childSize.height + verticalMargins;
552
+ } else {
553
+ width = childSize.width + horizontalMargins;
554
+ height = childSize.height;
549
555
}
550
556
551
557
return _Sizes (constraints.constrain (Size (width, height)), childSize);
@@ -575,26 +581,14 @@ class RenderCSSBox extends RenderBox
575
581
576
582
double leftOffset = 0 ;
577
583
double topOffset = 0 ;
578
- switch (display) {
579
- case Display .block:
580
- leftOffset = leftMargin;
581
- topOffset = topMargin;
582
- break ;
583
- case Display .inline:
584
- leftOffset = leftMargin;
585
- break ;
586
- case Display .inlineBlock:
587
- leftOffset = leftMargin;
588
- topOffset = topMargin;
589
- break ;
590
- case Display .listItem:
591
- leftOffset = leftMargin;
592
- topOffset = topMargin;
593
- break ;
594
- case Display .none:
595
- //No offset
596
- break ;
584
+
585
+ if (display.isBlock || display == Display .inlineBlock) {
586
+ leftOffset = leftMargin;
587
+ topOffset = topMargin;
588
+ } else if (display.displayOutside == DisplayOutside .inline) {
589
+ leftOffset = leftMargin;
597
590
}
591
+
598
592
childParentData.offset = Offset (leftOffset, topOffset);
599
593
assert (child.parentData == childParentData);
600
594
@@ -628,7 +622,7 @@ class RenderCSSBox extends RenderBox
628
622
629
623
Margins _calculateUsedMargins (Size childSize, Size containingBlockSize) {
630
624
//We assume that margins have already been preprocessed
631
- // (i.e. they are non-null and either px units or auto.
625
+ // (i.e. they are non-null and either px units or auto) .
632
626
assert (margins.left != null && margins.right != null );
633
627
assert (margins.left! .unit == Unit .px || margins.left! .unit == Unit .auto);
634
628
assert (margins.right! .unit == Unit .px || margins.right! .unit == Unit .auto);
@@ -737,6 +731,40 @@ class RenderCSSBox extends RenderBox
737
731
);
738
732
}
739
733
734
+ Margins _calculateIntrinsicMargins () {
735
+ //We assume that margins have already been preprocessed
736
+ // (i.e. they are non-null and either px units or auto).
737
+ assert (margins.left != null && margins.right != null );
738
+ assert (margins.left! .unit == Unit .px || margins.left! .unit == Unit .auto);
739
+ assert (margins.right! .unit == Unit .px || margins.right! .unit == Unit .auto);
740
+
741
+ Margin marginLeft = margins.left! ;
742
+ Margin marginRight = margins.right! ;
743
+
744
+ bool marginLeftIsAuto = marginLeft.unit == Unit .auto;
745
+ bool marginRightIsAuto = marginRight.unit == Unit .auto;
746
+
747
+ if (display.isBlock) {
748
+ if (marginLeftIsAuto) {
749
+ marginLeft = Margin (0 );
750
+ }
751
+
752
+ if (marginRightIsAuto) {
753
+ marginRight = Margin (0 );
754
+ }
755
+ } else {
756
+ marginLeft = Margin (0 );
757
+ marginRight = Margin (0 );
758
+ }
759
+
760
+ return Margins (
761
+ left: marginLeft,
762
+ right: marginRight,
763
+ top: margins.top,
764
+ bottom: margins.bottom,
765
+ );
766
+ }
767
+
740
768
@override
741
769
bool hitTestChildren (BoxHitTestResult result, {required Offset position}) {
742
770
return defaultHitTestChildren (result, position: position);
0 commit comments