@@ -12,6 +12,7 @@ class CssBoxWidget extends StatelessWidget {
12
12
this .textDirection,
13
13
this .childIsReplaced = false ,
14
14
this .shrinkWrap = false ,
15
+ this .top = false ,
15
16
});
16
17
17
18
/// Generates a CSSBoxWidget that contains a list of InlineSpan children.
@@ -23,6 +24,7 @@ class CssBoxWidget extends StatelessWidget {
23
24
this .childIsReplaced = false ,
24
25
this .shrinkWrap = false ,
25
26
bool selectable = false ,
27
+ this .top = false ,
26
28
TextSelectionControls ? selectionControls,
27
29
ScrollPhysics ? scrollPhysics,
28
30
}) : child = selectable
@@ -55,11 +57,12 @@ class CssBoxWidget extends StatelessWidget {
55
57
/// necessarily take up the full available width unless necessary
56
58
final bool shrinkWrap;
57
59
60
+ /// For the root widget, so textScaleFactor etc are only applied once
61
+ final bool top;
62
+
58
63
@override
59
64
Widget build (BuildContext context) {
60
- final markerBox = style.listStylePosition == ListStylePosition .outside
61
- ? _generateMarkerBoxSpan (style)
62
- : null ;
65
+ final markerBox = style.listStylePosition == ListStylePosition .outside ? _generateMarkerBoxSpan (style) : null ;
63
66
64
67
return _CSSBoxRenderer (
65
68
width: style.width ?? Width .auto (),
@@ -74,14 +77,13 @@ class CssBoxWidget extends StatelessWidget {
74
77
shrinkWrap: shrinkWrap,
75
78
children: [
76
79
Container (
77
- decoration: BoxDecoration (
78
- border: style.border,
79
- color: style.backgroundColor, //Colors the padding and content boxes
80
- ),
81
- width: _shouldExpandToFillBlock () ? double .infinity : null ,
82
- padding: style.padding ?? EdgeInsets .zero,
83
- child: child,
84
- ),
80
+ decoration: BoxDecoration (
81
+ border: style.border,
82
+ color: style.backgroundColor, //Colors the padding and content boxes
83
+ ),
84
+ width: _shouldExpandToFillBlock () ? double .infinity : null ,
85
+ padding: style.padding ?? EdgeInsets .zero,
86
+ child: top ? child : MediaQuery (data: MediaQuery .of (context).copyWith (textScaleFactor: 1.0 ), child: child)),
85
87
if (markerBox != null ) Text .rich (markerBox),
86
88
],
87
89
);
@@ -103,8 +105,8 @@ class CssBoxWidget extends StatelessWidget {
103
105
}
104
106
}
105
107
106
- return RichText (
107
- text : TextSpan (
108
+ return Text . rich (
109
+ TextSpan (
108
110
style: style.generateTextStyle (),
109
111
children: children,
110
112
),
@@ -148,8 +150,7 @@ class CssBoxWidget extends StatelessWidget {
148
150
child: Image .network (
149
151
style.listStyleImage! .uriText,
150
152
errorBuilder: (_, __, ___) {
151
- if (style.marker? .content.replacementContent? .isNotEmpty ??
152
- false ) {
153
+ if (style.marker? .content.replacementContent? .isNotEmpty ?? false ) {
153
154
return Text .rich (
154
155
TextSpan (
155
156
text: style.marker! .content.replacementContent! ,
@@ -180,14 +181,10 @@ class CssBoxWidget extends StatelessWidget {
180
181
/// width available to it or if it should just let its inner content
181
182
/// determine the content-box's width.
182
183
bool _shouldExpandToFillBlock () {
183
- return (style.display == Display .block ||
184
- style.display == Display .listItem) &&
185
- ! childIsReplaced &&
186
- ! shrinkWrap;
184
+ return (style.display == Display .block || style.display == Display .listItem) && ! childIsReplaced && ! shrinkWrap;
187
185
}
188
186
189
- TextDirection _checkTextDirection (
190
- BuildContext context, TextDirection ? direction) {
187
+ TextDirection _checkTextDirection (BuildContext context, TextDirection ? direction) {
191
188
final textDirection = direction ?? Directionality .maybeOf (context);
192
189
193
190
assert (
@@ -321,9 +318,7 @@ class _CSSBoxRenderer extends MultiChildRenderObjectWidget {
321
318
322
319
/// Implements the CSS layout algorithm
323
320
class _RenderCSSBox extends RenderBox
324
- with
325
- ContainerRenderObjectMixin <RenderBox , CSSBoxParentData >,
326
- RenderBoxContainerDefaultsMixin <RenderBox , CSSBoxParentData > {
321
+ with ContainerRenderObjectMixin <RenderBox , CSSBoxParentData >, RenderBoxContainerDefaultsMixin <RenderBox , CSSBoxParentData > {
327
322
_RenderCSSBox ({
328
323
required Display display,
329
324
required Width width,
@@ -432,13 +427,11 @@ class _RenderCSSBox extends RenderBox
432
427
}
433
428
}
434
429
435
- static double getIntrinsicDimension (RenderBox ? firstChild,
436
- double Function (RenderBox child) mainChildSizeGetter) {
430
+ static double getIntrinsicDimension (RenderBox ? firstChild, double Function (RenderBox child) mainChildSizeGetter) {
437
431
double extent = 0.0 ;
438
432
RenderBox ? child = firstChild;
439
433
while (child != null ) {
440
- final CSSBoxParentData childParentData =
441
- child.parentData! as CSSBoxParentData ;
434
+ final CSSBoxParentData childParentData = child.parentData! as CSSBoxParentData ;
442
435
extent = math.max (extent, mainChildSizeGetter (child));
443
436
assert (child.parentData == childParentData);
444
437
child = childParentData.nextSibling;
@@ -448,26 +441,22 @@ class _RenderCSSBox extends RenderBox
448
441
449
442
@override
450
443
double computeMinIntrinsicWidth (double height) {
451
- return getIntrinsicDimension (
452
- firstChild, (RenderBox child) => child.getMinIntrinsicWidth (height));
444
+ return getIntrinsicDimension (firstChild, (RenderBox child) => child.getMinIntrinsicWidth (height));
453
445
}
454
446
455
447
@override
456
448
double computeMaxIntrinsicWidth (double height) {
457
- return getIntrinsicDimension (
458
- firstChild, (RenderBox child) => child.getMaxIntrinsicWidth (height));
449
+ return getIntrinsicDimension (firstChild, (RenderBox child) => child.getMaxIntrinsicWidth (height));
459
450
}
460
451
461
452
@override
462
453
double computeMinIntrinsicHeight (double width) {
463
- return getIntrinsicDimension (
464
- firstChild, (RenderBox child) => child.getMinIntrinsicHeight (width));
454
+ return getIntrinsicDimension (firstChild, (RenderBox child) => child.getMinIntrinsicHeight (width));
465
455
}
466
456
467
457
@override
468
458
double computeMaxIntrinsicHeight (double width) {
469
- return getIntrinsicDimension (
470
- firstChild, (RenderBox child) => child.getMaxIntrinsicHeight (width));
459
+ return getIntrinsicDimension (firstChild, (RenderBox child) => child.getMaxIntrinsicHeight (width));
471
460
}
472
461
473
462
@override
@@ -483,9 +472,7 @@ class _RenderCSSBox extends RenderBox
483
472
).parentSize;
484
473
}
485
474
486
- _Sizes _computeSize (
487
- {required BoxConstraints constraints,
488
- required ChildLayouter layoutChild}) {
475
+ _Sizes _computeSize ({required BoxConstraints constraints, required ChildLayouter layoutChild}) {
489
476
if (childCount == 0 ) {
490
477
return _Sizes (constraints.biggest, Size .zero);
491
478
}
@@ -504,14 +491,10 @@ class _RenderCSSBox extends RenderBox
504
491
final childConstraints = constraints.copyWith (
505
492
maxWidth: (this .width.unit != Unit .auto)
506
493
? this .width.value
507
- : containingBlockSize.width -
508
- (margins.left? .value ?? 0 ) -
509
- (margins.right? .value ?? 0 ),
494
+ : containingBlockSize.width - (margins.left? .value ?? 0 ) - (margins.right? .value ?? 0 ),
510
495
maxHeight: (this .height.unit != Unit .auto)
511
496
? this .height.value
512
- : containingBlockSize.height -
513
- (margins.top? .value ?? 0 ) -
514
- (margins.bottom? .value ?? 0 ),
497
+ : containingBlockSize.height - (margins.top? .value ?? 0 ) - (margins.bottom? .value ?? 0 ),
515
498
minWidth: (this .width.unit != Unit .auto) ? this .width.value : 0 ,
516
499
minHeight: (this .height.unit != Unit .auto) ? this .height.value : 0 ,
517
500
);
@@ -522,18 +505,14 @@ class _RenderCSSBox extends RenderBox
522
505
523
506
// Calculate used values of margins based on rules
524
507
final usedMargins = _calculateUsedMargins (childSize, containingBlockSize);
525
- final horizontalMargins =
526
- (usedMargins.left? .value ?? 0 ) + (usedMargins.right? .value ?? 0 );
527
- final verticalMargins =
528
- (usedMargins.top? .value ?? 0 ) + (usedMargins.bottom? .value ?? 0 );
508
+ final horizontalMargins = (usedMargins.left? .value ?? 0 ) + (usedMargins.right? .value ?? 0 );
509
+ final verticalMargins = (usedMargins.top? .value ?? 0 ) + (usedMargins.bottom? .value ?? 0 );
529
510
530
511
//Calculate Width and Height of CSS Box
531
512
height = childSize.height;
532
513
switch (display) {
533
514
case Display .block:
534
- width = (shrinkWrap || childIsReplaced)
535
- ? childSize.width + horizontalMargins
536
- : containingBlockSize.width;
515
+ width = (shrinkWrap || childIsReplaced) ? childSize.width + horizontalMargins : containingBlockSize.width;
537
516
height = childSize.height + verticalMargins;
538
517
break ;
539
518
case Display .inline:
@@ -545,9 +524,7 @@ class _RenderCSSBox extends RenderBox
545
524
height = childSize.height + verticalMargins;
546
525
break ;
547
526
case Display .listItem:
548
- width = shrinkWrap
549
- ? childSize.width + horizontalMargins
550
- : containingBlockSize.width;
527
+ width = shrinkWrap ? childSize.width + horizontalMargins : containingBlockSize.width;
551
528
height = childSize.height + verticalMargins;
552
529
break ;
553
530
case Display .none:
@@ -572,12 +549,10 @@ class _RenderCSSBox extends RenderBox
572
549
assert (firstChild != null );
573
550
RenderBox child = firstChild! ;
574
551
575
- final CSSBoxParentData childParentData =
576
- child.parentData! as CSSBoxParentData ;
552
+ final CSSBoxParentData childParentData = child.parentData! as CSSBoxParentData ;
577
553
578
554
// Calculate used margins based on constraints and child size
579
- final usedMargins =
580
- _calculateUsedMargins (sizes.childSize, constraints.biggest);
555
+ final usedMargins = _calculateUsedMargins (sizes.childSize, constraints.biggest);
581
556
final leftMargin = usedMargins.left? .value ?? 0 ;
582
557
final topMargin = usedMargins.top? .value ?? 0 ;
583
558
@@ -610,13 +585,8 @@ class _RenderCSSBox extends RenderBox
610
585
RenderBox ? markerBox = childParentData.nextSibling;
611
586
if (markerBox != null ) {
612
587
final markerBoxParentData = markerBox.parentData! as CSSBoxParentData ;
613
- final distance = (child.getDistanceToBaseline (TextBaseline .alphabetic,
614
- onlyReal: true ) ??
615
- 0 ) +
616
- topOffset;
617
- final offsetHeight = distance -
618
- (markerBox.getDistanceToBaseline (TextBaseline .alphabetic) ??
619
- markerBox.size.height);
588
+ final distance = (child.getDistanceToBaseline (TextBaseline .alphabetic, onlyReal: true ) ?? 0 ) + topOffset;
589
+ final offsetHeight = distance - (markerBox.getDistanceToBaseline (TextBaseline .alphabetic) ?? markerBox.size.height);
620
590
markerBoxParentData.offset = Offset (- markerBox.size.width, offsetHeight);
621
591
}
622
592
}
@@ -648,8 +618,7 @@ class _RenderCSSBox extends RenderBox
648
618
// width of the containing block, then consider left and right margins to
649
619
// have a 0 value.
650
620
if (! widthIsAuto) {
651
- if ((childSize.width + marginLeft.value + marginRight.value) >
652
- containingBlockSize.width) {
621
+ if ((childSize.width + marginLeft.value + marginRight.value) > containingBlockSize.width) {
653
622
//Treat auto values of margin left and margin right as 0 for following rules
654
623
marginLeft = Margin (0 );
655
624
marginRight = Margin (0 );
@@ -661,22 +630,16 @@ class _RenderCSSBox extends RenderBox
661
630
// If all values are non-auto, the box is overconstrained.
662
631
// One of the margins will need to be adjusted so that the
663
632
// entire width of the containing block is used.
664
- if (! widthIsAuto &&
665
- ! marginLeftIsAuto &&
666
- ! marginRightIsAuto &&
667
- ! shrinkWrap &&
668
- ! childIsReplaced) {
633
+ if (! widthIsAuto && ! marginLeftIsAuto && ! marginRightIsAuto && ! shrinkWrap && ! childIsReplaced) {
669
634
//Ignore either left or right margin based on textDirection.
670
635
671
636
switch (textDirection) {
672
637
case TextDirection .rtl:
673
- final difference =
674
- containingBlockSize.width - childSize.width - marginRight.value;
638
+ final difference = containingBlockSize.width - childSize.width - marginRight.value;
675
639
marginLeft = Margin (difference);
676
640
break ;
677
641
case TextDirection .ltr:
678
- final difference =
679
- containingBlockSize.width - childSize.width - marginLeft.value;
642
+ final difference = containingBlockSize.width - childSize.width - marginLeft.value;
680
643
marginRight = Margin (difference);
681
644
break ;
682
645
}
@@ -686,12 +649,10 @@ class _RenderCSSBox extends RenderBox
686
649
if (widthIsAuto && ! marginLeftIsAuto && ! marginRightIsAuto) {
687
650
widthIsAuto = false ;
688
651
} else if (! widthIsAuto && marginLeftIsAuto && ! marginRightIsAuto) {
689
- marginLeft = Margin (
690
- containingBlockSize.width - childSize.width - marginRight.value);
652
+ marginLeft = Margin (containingBlockSize.width - childSize.width - marginRight.value);
691
653
marginLeftIsAuto = false ;
692
654
} else if (! widthIsAuto && ! marginLeftIsAuto && marginRightIsAuto) {
693
- marginRight = Margin (
694
- containingBlockSize.width - childSize.width - marginLeft.value);
655
+ marginRight = Margin (containingBlockSize.width - childSize.width - marginLeft.value);
695
656
marginRightIsAuto = false ;
696
657
}
697
658
@@ -712,8 +673,7 @@ class _RenderCSSBox extends RenderBox
712
673
//If both margin-left and margin-right are auto, their used values are equal.
713
674
// This horizontally centers the element within the containing block.
714
675
if (marginLeftIsAuto && marginRightIsAuto) {
715
- final newMargin =
716
- Margin ((containingBlockSize.width - childSize.width) / 2 );
676
+ final newMargin = Margin ((containingBlockSize.width - childSize.width) / 2 );
717
677
marginLeft = newMargin;
718
678
marginRight = newMargin;
719
679
marginLeftIsAuto = false ;
@@ -724,11 +684,7 @@ class _RenderCSSBox extends RenderBox
724
684
assert (! marginLeftIsAuto && ! marginRightIsAuto && ! widthIsAuto);
725
685
}
726
686
727
- return Margins (
728
- left: marginLeft,
729
- right: marginRight,
730
- top: margins.top,
731
- bottom: margins.bottom);
687
+ return Margins (left: marginLeft, right: marginRight, top: margins.top, bottom: margins.bottom);
732
688
}
733
689
734
690
@override
0 commit comments