@@ -62,7 +62,9 @@ class CssBoxWidget extends StatelessWidget {
62
62
63
63
@override
64
64
Widget build (BuildContext context) {
65
- final markerBox = style.listStylePosition == ListStylePosition .outside ? _generateMarkerBoxSpan (style) : null ;
65
+ final markerBox = style.listStylePosition == ListStylePosition .outside
66
+ ? _generateMarkerBoxSpan (style)
67
+ : null ;
66
68
67
69
return _CSSBoxRenderer (
68
70
width: style.width ?? Width .auto (),
@@ -79,11 +81,16 @@ class CssBoxWidget extends StatelessWidget {
79
81
Container (
80
82
decoration: BoxDecoration (
81
83
border: style.border,
82
- color: style.backgroundColor, //Colors the padding and content boxes
84
+ color:
85
+ style.backgroundColor, //Colors the padding and content boxes
83
86
),
84
87
width: _shouldExpandToFillBlock () ? double .infinity : null ,
85
88
padding: style.padding ?? EdgeInsets .zero,
86
- child: top ? child : MediaQuery (data: MediaQuery .of (context).copyWith (textScaleFactor: 1.0 ), child: child)),
89
+ child: top
90
+ ? child
91
+ : MediaQuery (
92
+ data: MediaQuery .of (context).copyWith (textScaleFactor: 1.0 ),
93
+ child: child)),
87
94
if (markerBox != null ) Text .rich (markerBox),
88
95
],
89
96
);
@@ -150,7 +157,8 @@ class CssBoxWidget extends StatelessWidget {
150
157
child: Image .network (
151
158
style.listStyleImage! .uriText,
152
159
errorBuilder: (_, __, ___) {
153
- if (style.marker? .content.replacementContent? .isNotEmpty ?? false ) {
160
+ if (style.marker? .content.replacementContent? .isNotEmpty ??
161
+ false ) {
154
162
return Text .rich (
155
163
TextSpan (
156
164
text: style.marker! .content.replacementContent! ,
@@ -181,10 +189,14 @@ class CssBoxWidget extends StatelessWidget {
181
189
/// width available to it or if it should just let its inner content
182
190
/// determine the content-box's width.
183
191
bool _shouldExpandToFillBlock () {
184
- return (style.display == Display .block || style.display == Display .listItem) && ! childIsReplaced && ! shrinkWrap;
192
+ return (style.display == Display .block ||
193
+ style.display == Display .listItem) &&
194
+ ! childIsReplaced &&
195
+ ! shrinkWrap;
185
196
}
186
197
187
- TextDirection _checkTextDirection (BuildContext context, TextDirection ? direction) {
198
+ TextDirection _checkTextDirection (
199
+ BuildContext context, TextDirection ? direction) {
188
200
final textDirection = direction ?? Directionality .maybeOf (context);
189
201
190
202
assert (
@@ -318,7 +330,9 @@ class _CSSBoxRenderer extends MultiChildRenderObjectWidget {
318
330
319
331
/// Implements the CSS layout algorithm
320
332
class _RenderCSSBox extends RenderBox
321
- with ContainerRenderObjectMixin <RenderBox , CSSBoxParentData >, RenderBoxContainerDefaultsMixin <RenderBox , CSSBoxParentData > {
333
+ with
334
+ ContainerRenderObjectMixin <RenderBox , CSSBoxParentData >,
335
+ RenderBoxContainerDefaultsMixin <RenderBox , CSSBoxParentData > {
322
336
_RenderCSSBox ({
323
337
required Display display,
324
338
required Width width,
@@ -427,11 +441,13 @@ class _RenderCSSBox extends RenderBox
427
441
}
428
442
}
429
443
430
- static double getIntrinsicDimension (RenderBox ? firstChild, double Function (RenderBox child) mainChildSizeGetter) {
444
+ static double getIntrinsicDimension (RenderBox ? firstChild,
445
+ double Function (RenderBox child) mainChildSizeGetter) {
431
446
double extent = 0.0 ;
432
447
RenderBox ? child = firstChild;
433
448
while (child != null ) {
434
- final CSSBoxParentData childParentData = child.parentData! as CSSBoxParentData ;
449
+ final CSSBoxParentData childParentData =
450
+ child.parentData! as CSSBoxParentData ;
435
451
extent = math.max (extent, mainChildSizeGetter (child));
436
452
assert (child.parentData == childParentData);
437
453
child = childParentData.nextSibling;
@@ -441,22 +457,26 @@ class _RenderCSSBox extends RenderBox
441
457
442
458
@override
443
459
double computeMinIntrinsicWidth (double height) {
444
- return getIntrinsicDimension (firstChild, (RenderBox child) => child.getMinIntrinsicWidth (height));
460
+ return getIntrinsicDimension (
461
+ firstChild, (RenderBox child) => child.getMinIntrinsicWidth (height));
445
462
}
446
463
447
464
@override
448
465
double computeMaxIntrinsicWidth (double height) {
449
- return getIntrinsicDimension (firstChild, (RenderBox child) => child.getMaxIntrinsicWidth (height));
466
+ return getIntrinsicDimension (
467
+ firstChild, (RenderBox child) => child.getMaxIntrinsicWidth (height));
450
468
}
451
469
452
470
@override
453
471
double computeMinIntrinsicHeight (double width) {
454
- return getIntrinsicDimension (firstChild, (RenderBox child) => child.getMinIntrinsicHeight (width));
472
+ return getIntrinsicDimension (
473
+ firstChild, (RenderBox child) => child.getMinIntrinsicHeight (width));
455
474
}
456
475
457
476
@override
458
477
double computeMaxIntrinsicHeight (double width) {
459
- return getIntrinsicDimension (firstChild, (RenderBox child) => child.getMaxIntrinsicHeight (width));
478
+ return getIntrinsicDimension (
479
+ firstChild, (RenderBox child) => child.getMaxIntrinsicHeight (width));
460
480
}
461
481
462
482
@override
@@ -472,7 +492,9 @@ class _RenderCSSBox extends RenderBox
472
492
).parentSize;
473
493
}
474
494
475
- _Sizes _computeSize ({required BoxConstraints constraints, required ChildLayouter layoutChild}) {
495
+ _Sizes _computeSize (
496
+ {required BoxConstraints constraints,
497
+ required ChildLayouter layoutChild}) {
476
498
if (childCount == 0 ) {
477
499
return _Sizes (constraints.biggest, Size .zero);
478
500
}
@@ -491,10 +513,14 @@ class _RenderCSSBox extends RenderBox
491
513
final childConstraints = constraints.copyWith (
492
514
maxWidth: (this .width.unit != Unit .auto)
493
515
? this .width.value
494
- : containingBlockSize.width - (margins.left? .value ?? 0 ) - (margins.right? .value ?? 0 ),
516
+ : containingBlockSize.width -
517
+ (margins.left? .value ?? 0 ) -
518
+ (margins.right? .value ?? 0 ),
495
519
maxHeight: (this .height.unit != Unit .auto)
496
520
? this .height.value
497
- : containingBlockSize.height - (margins.top? .value ?? 0 ) - (margins.bottom? .value ?? 0 ),
521
+ : containingBlockSize.height -
522
+ (margins.top? .value ?? 0 ) -
523
+ (margins.bottom? .value ?? 0 ),
498
524
minWidth: (this .width.unit != Unit .auto) ? this .width.value : 0 ,
499
525
minHeight: (this .height.unit != Unit .auto) ? this .height.value : 0 ,
500
526
);
@@ -505,14 +531,18 @@ class _RenderCSSBox extends RenderBox
505
531
506
532
// Calculate used values of margins based on rules
507
533
final usedMargins = _calculateUsedMargins (childSize, containingBlockSize);
508
- final horizontalMargins = (usedMargins.left? .value ?? 0 ) + (usedMargins.right? .value ?? 0 );
509
- final verticalMargins = (usedMargins.top? .value ?? 0 ) + (usedMargins.bottom? .value ?? 0 );
534
+ final horizontalMargins =
535
+ (usedMargins.left? .value ?? 0 ) + (usedMargins.right? .value ?? 0 );
536
+ final verticalMargins =
537
+ (usedMargins.top? .value ?? 0 ) + (usedMargins.bottom? .value ?? 0 );
510
538
511
539
//Calculate Width and Height of CSS Box
512
540
height = childSize.height;
513
541
switch (display) {
514
542
case Display .block:
515
- width = (shrinkWrap || childIsReplaced) ? childSize.width + horizontalMargins : containingBlockSize.width;
543
+ width = (shrinkWrap || childIsReplaced)
544
+ ? childSize.width + horizontalMargins
545
+ : containingBlockSize.width;
516
546
height = childSize.height + verticalMargins;
517
547
break ;
518
548
case Display .inline:
@@ -524,7 +554,9 @@ class _RenderCSSBox extends RenderBox
524
554
height = childSize.height + verticalMargins;
525
555
break ;
526
556
case Display .listItem:
527
- width = shrinkWrap ? childSize.width + horizontalMargins : containingBlockSize.width;
557
+ width = shrinkWrap
558
+ ? childSize.width + horizontalMargins
559
+ : containingBlockSize.width;
528
560
height = childSize.height + verticalMargins;
529
561
break ;
530
562
case Display .none:
@@ -549,10 +581,12 @@ class _RenderCSSBox extends RenderBox
549
581
assert (firstChild != null );
550
582
RenderBox child = firstChild! ;
551
583
552
- final CSSBoxParentData childParentData = child.parentData! as CSSBoxParentData ;
584
+ final CSSBoxParentData childParentData =
585
+ child.parentData! as CSSBoxParentData ;
553
586
554
587
// Calculate used margins based on constraints and child size
555
- final usedMargins = _calculateUsedMargins (sizes.childSize, constraints.biggest);
588
+ final usedMargins =
589
+ _calculateUsedMargins (sizes.childSize, constraints.biggest);
556
590
final leftMargin = usedMargins.left? .value ?? 0 ;
557
591
final topMargin = usedMargins.top? .value ?? 0 ;
558
592
@@ -585,8 +619,13 @@ class _RenderCSSBox extends RenderBox
585
619
RenderBox ? markerBox = childParentData.nextSibling;
586
620
if (markerBox != null ) {
587
621
final markerBoxParentData = markerBox.parentData! as CSSBoxParentData ;
588
- final distance = (child.getDistanceToBaseline (TextBaseline .alphabetic, onlyReal: true ) ?? 0 ) + topOffset;
589
- final offsetHeight = distance - (markerBox.getDistanceToBaseline (TextBaseline .alphabetic) ?? markerBox.size.height);
622
+ final distance = (child.getDistanceToBaseline (TextBaseline .alphabetic,
623
+ onlyReal: true ) ??
624
+ 0 ) +
625
+ topOffset;
626
+ final offsetHeight = distance -
627
+ (markerBox.getDistanceToBaseline (TextBaseline .alphabetic) ??
628
+ markerBox.size.height);
590
629
markerBoxParentData.offset = Offset (- markerBox.size.width, offsetHeight);
591
630
}
592
631
}
@@ -618,7 +657,8 @@ class _RenderCSSBox extends RenderBox
618
657
// width of the containing block, then consider left and right margins to
619
658
// have a 0 value.
620
659
if (! widthIsAuto) {
621
- if ((childSize.width + marginLeft.value + marginRight.value) > containingBlockSize.width) {
660
+ if ((childSize.width + marginLeft.value + marginRight.value) >
661
+ containingBlockSize.width) {
622
662
//Treat auto values of margin left and margin right as 0 for following rules
623
663
marginLeft = Margin (0 );
624
664
marginRight = Margin (0 );
@@ -630,16 +670,22 @@ class _RenderCSSBox extends RenderBox
630
670
// If all values are non-auto, the box is overconstrained.
631
671
// One of the margins will need to be adjusted so that the
632
672
// entire width of the containing block is used.
633
- if (! widthIsAuto && ! marginLeftIsAuto && ! marginRightIsAuto && ! shrinkWrap && ! childIsReplaced) {
673
+ if (! widthIsAuto &&
674
+ ! marginLeftIsAuto &&
675
+ ! marginRightIsAuto &&
676
+ ! shrinkWrap &&
677
+ ! childIsReplaced) {
634
678
//Ignore either left or right margin based on textDirection.
635
679
636
680
switch (textDirection) {
637
681
case TextDirection .rtl:
638
- final difference = containingBlockSize.width - childSize.width - marginRight.value;
682
+ final difference =
683
+ containingBlockSize.width - childSize.width - marginRight.value;
639
684
marginLeft = Margin (difference);
640
685
break ;
641
686
case TextDirection .ltr:
642
- final difference = containingBlockSize.width - childSize.width - marginLeft.value;
687
+ final difference =
688
+ containingBlockSize.width - childSize.width - marginLeft.value;
643
689
marginRight = Margin (difference);
644
690
break ;
645
691
}
@@ -649,10 +695,12 @@ class _RenderCSSBox extends RenderBox
649
695
if (widthIsAuto && ! marginLeftIsAuto && ! marginRightIsAuto) {
650
696
widthIsAuto = false ;
651
697
} else if (! widthIsAuto && marginLeftIsAuto && ! marginRightIsAuto) {
652
- marginLeft = Margin (containingBlockSize.width - childSize.width - marginRight.value);
698
+ marginLeft = Margin (
699
+ containingBlockSize.width - childSize.width - marginRight.value);
653
700
marginLeftIsAuto = false ;
654
701
} else if (! widthIsAuto && ! marginLeftIsAuto && marginRightIsAuto) {
655
- marginRight = Margin (containingBlockSize.width - childSize.width - marginLeft.value);
702
+ marginRight = Margin (
703
+ containingBlockSize.width - childSize.width - marginLeft.value);
656
704
marginRightIsAuto = false ;
657
705
}
658
706
@@ -673,7 +721,8 @@ class _RenderCSSBox extends RenderBox
673
721
//If both margin-left and margin-right are auto, their used values are equal.
674
722
// This horizontally centers the element within the containing block.
675
723
if (marginLeftIsAuto && marginRightIsAuto) {
676
- final newMargin = Margin ((containingBlockSize.width - childSize.width) / 2 );
724
+ final newMargin =
725
+ Margin ((containingBlockSize.width - childSize.width) / 2 );
677
726
marginLeft = newMargin;
678
727
marginRight = newMargin;
679
728
marginLeftIsAuto = false ;
@@ -684,7 +733,11 @@ class _RenderCSSBox extends RenderBox
684
733
assert (! marginLeftIsAuto && ! marginRightIsAuto && ! widthIsAuto);
685
734
}
686
735
687
- return Margins (left: marginLeft, right: marginRight, top: margins.top, bottom: margins.bottom);
736
+ return Margins (
737
+ left: marginLeft,
738
+ right: marginRight,
739
+ top: margins.top,
740
+ bottom: margins.bottom);
688
741
}
689
742
690
743
@override
0 commit comments