Skip to content

Commit 4061a6a

Browse files
committed
Remove BuildTree.apply
1 parent f2911bd commit 4061a6a

File tree

10 files changed

+31
-37
lines changed

10 files changed

+31
-37
lines changed

packages/core/lib/src/core_widget_factory.dart

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ class WidgetFactory extends WidgetFactoryResetter with AnchorWidgetFactory {
609609
case kTagA:
610610
if (attrs.containsKey(kAttributeAHref)) {
611611
tree
612-
..apply<BuildContext?>(TagA.defaultColor, null)
612+
..styleBuilder.enqueue<BuildContext?>(TagA.defaultColor)
613613
..register(_tagA ??= TagA(this).buildOp);
614614
}
615615

@@ -672,14 +672,16 @@ class WidgetFactory extends WidgetFactoryResetter with AnchorWidgetFactory {
672672

673673
case 'b':
674674
case 'strong':
675-
tree.apply(TextStyleOps.fontWeight, FontWeight.bold);
675+
tree.styleBuilder.enqueue(TextStyleOps.fontWeight, FontWeight.bold);
676676
break;
677677

678678
case 'big':
679-
tree.apply(TextStyleOps.fontSizeTerm, kCssFontSizeLarger);
679+
tree.styleBuilder
680+
.enqueue(TextStyleOps.fontSizeTerm, kCssFontSizeLarger);
680681
break;
681682
case 'small':
682-
tree.apply(TextStyleOps.fontSizeTerm, kCssFontSizeSmaller);
683+
tree.styleBuilder
684+
.enqueue(TextStyleOps.fontSizeTerm, kCssFontSizeSmaller);
683685
break;
684686

685687
case kTagBr:
@@ -701,14 +703,14 @@ class WidgetFactory extends WidgetFactoryResetter with AnchorWidgetFactory {
701703
case 'em':
702704
case 'i':
703705
case 'var':
704-
tree.apply(TextStyleOps.fontStyle, FontStyle.italic);
706+
tree.styleBuilder.enqueue(TextStyleOps.fontStyle, FontStyle.italic);
705707
break;
706708

707709
case kTagCode:
708710
case kTagKbd:
709711
case kTagSamp:
710712
case kTagTt:
711-
tree.apply(
713+
tree.styleBuilder.enqueue(
712714
TextStyleOps.fontFamily,
713715
const [kTagCodeFont1, kTagCodeFont2],
714716
);
@@ -985,26 +987,26 @@ class WidgetFactory extends WidgetFactoryResetter with AnchorWidgetFactory {
985987
case kCssColor:
986988
final color = tryParseColor(style.value);
987989
if (color != null) {
988-
tree.apply(TextStyleOps.color, color);
990+
tree.styleBuilder.enqueue(TextStyleOps.color, color);
989991
}
990992
break;
991993

992994
case kCssDirection:
993995
final term = style.term;
994996
if (term != null) {
995-
tree.apply(TextStyleOps.textDirection, term);
997+
tree.styleBuilder.enqueue(TextStyleOps.textDirection, term);
996998
}
997999
break;
9981000

9991001
case kCssFontFamily:
10001002
final list = TextStyleOps.fontFamilyTryParse(style.values);
1001-
tree.apply(TextStyleOps.fontFamily, list);
1003+
tree.styleBuilder.enqueue(TextStyleOps.fontFamily, list);
10021004
break;
10031005

10041006
case kCssFontSize:
10051007
final value = style.value;
10061008
if (value != null) {
1007-
tree.apply(TextStyleOps.fontSize, value);
1009+
tree.styleBuilder.enqueue(TextStyleOps.fontSize, value);
10081010
}
10091011
break;
10101012

@@ -1013,7 +1015,7 @@ class WidgetFactory extends WidgetFactoryResetter with AnchorWidgetFactory {
10131015
final fontStyle =
10141016
term != null ? TextStyleOps.fontStyleTryParse(term) : null;
10151017
if (fontStyle != null) {
1016-
tree.apply(TextStyleOps.fontStyle, fontStyle);
1018+
tree.styleBuilder.enqueue(TextStyleOps.fontStyle, fontStyle);
10171019
}
10181020
break;
10191021

@@ -1022,7 +1024,7 @@ class WidgetFactory extends WidgetFactoryResetter with AnchorWidgetFactory {
10221024
final fontWeight =
10231025
value != null ? TextStyleOps.fontWeightTryParse(value) : null;
10241026
if (fontWeight != null) {
1025-
tree.apply(TextStyleOps.fontWeight, fontWeight);
1027+
tree.styleBuilder.enqueue(TextStyleOps.fontWeight, fontWeight);
10261028
}
10271029
break;
10281030

@@ -1038,7 +1040,7 @@ class WidgetFactory extends WidgetFactoryResetter with AnchorWidgetFactory {
10381040
case kCssLineHeight:
10391041
final value = style.value;
10401042
if (value != null) {
1041-
tree.apply(
1043+
tree.styleBuilder.enqueue(
10421044
_styleBuilderLineHeight ??= TextStyleOps.lineHeight(this),
10431045
value,
10441046
);
@@ -1082,7 +1084,7 @@ class WidgetFactory extends WidgetFactoryResetter with AnchorWidgetFactory {
10821084
final whitespace =
10831085
term != null ? TextStyleOps.whitespaceTryParse(term) : null;
10841086
if (whitespace != null) {
1085-
tree.apply(TextStyleOps.whitespace, whitespace);
1087+
tree.styleBuilder.enqueue(TextStyleOps.whitespace, whitespace);
10861088
}
10871089
break;
10881090
}

packages/core/lib/src/data/build_bits.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,6 @@ abstract class BuildTree extends BuildBit {
200200
@Deprecated('Use .getStyle instead.')
201201
css.Declaration? operator [](String key) => getStyle(key);
202202

203-
/// {@macro flutter_widget_from_html.enqueue}
204-
void apply<T>(
205-
HtmlStyle Function(HtmlStyle style, T input) callback,
206-
T input,
207-
) =>
208-
styleBuilder.enqueue(callback, input);
209-
210203
/// Appends [bit].
211204
///
212205
/// See also: [prepend].

packages/core/lib/src/data/html_style.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,15 @@ class HtmlStyleBuilder {
8989

9090
HtmlStyleBuilder([this.parent, this._queue]);
9191

92-
/// {@template flutter_widget_from_html.enqueue}
9392
/// Enqueues an HTML styling callback.
9493
///
9594
/// The callback will receive the current [HtmlStyle] being built.
9695
/// As a special case, declare `T=BuildContext?` to receive the [BuildContext].
97-
/// {@endtemplate}
9896
void enqueue<T>(
99-
HtmlStyle Function(HtmlStyle style, T input) callback,
100-
T input,
101-
) {
102-
final item = _HtmlStyleCallback(callback, input);
97+
HtmlStyle Function(HtmlStyle style, T input) callback, [
98+
T? input,
99+
]) {
100+
final item = _HtmlStyleCallback(callback, input as T);
103101
final queue = _queue ??= [];
104102
queue.add(item);
105103
}

packages/core/lib/src/internal/ops/style_background.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class StyleBackground {
2727
return;
2828
}
2929

30-
tree.apply(_color, color);
30+
tree.styleBuilder.enqueue(_color, color);
3131
},
3232
priority: BoxModel.background,
3333
);

packages/core/lib/src/internal/ops/style_text_align.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension StyleTextAlign on WidgetFactory {
2929
static BuildTree _onParsed(BuildTree tree) {
3030
final textAlign = tree.textAlignData.textAlign;
3131
if (textAlign != null) {
32-
tree.apply(_textAlign, textAlign);
32+
tree.styleBuilder.enqueue(_textAlign, textAlign);
3333
}
3434
return tree;
3535
}

packages/core/lib/src/internal/ops/style_text_decoration.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void textDecorationApply(BuildTree tree, css.Declaration style) {
1717
style.property == kCssTextDecorationLine) {
1818
final line = TextDecorationLine.tryParse(value);
1919
if (line != null) {
20-
tree.apply(textDecorationLine, line);
20+
tree.styleBuilder.enqueue(textDecorationLine, line);
2121
continue;
2222
}
2323
}
@@ -26,7 +26,7 @@ void textDecorationApply(BuildTree tree, css.Declaration style) {
2626
style.property == kCssTextDecorationStyle) {
2727
final tds = tryParseTextDecorationStyle(value);
2828
if (tds != null) {
29-
tree.apply(textDecorationStyle, tds);
29+
tree.styleBuilder.enqueue(textDecorationStyle, tds);
3030
continue;
3131
}
3232
}
@@ -35,7 +35,7 @@ void textDecorationApply(BuildTree tree, css.Declaration style) {
3535
style.property == kCssTextDecorationColor) {
3636
final color = tryParseColor(value);
3737
if (color != null) {
38-
tree.apply(textDecorationColor, color);
38+
tree.styleBuilder.enqueue(textDecorationColor, color);
3939
continue;
4040
}
4141
}
@@ -45,7 +45,8 @@ void textDecorationApply(BuildTree tree, css.Declaration style) {
4545
style.property == kCssTextDecorationWidth) {
4646
final length = tryParseCssLength(value);
4747
if (length != null && length.unit == CssLengthUnit.percentage) {
48-
tree.apply(textDecorationThickness, length.number / 100.0);
48+
tree.styleBuilder
49+
.enqueue(textDecorationThickness, length.number / 100.0);
4950
continue;
5051
}
5152
}

packages/core/lib/src/internal/ops/tag_a.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TagA {
2727
return tree;
2828
}
2929

30-
return tree..apply(_builder, recognizer);
30+
return tree..styleBuilder.enqueue(_builder, recognizer);
3131
},
3232
priority: Priority.tagA,
3333
);

packages/core/lib/src/internal/ops/tag_li.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class TagLi {
7171
) {
7272
final tree = itemTree.sub()
7373
..maxLines = 1
74-
..apply(TextStyleOps.whitespace, CssWhitespace.nowrap);
74+
..styleBuilder.enqueue(TextStyleOps.whitespace, CssWhitespace.nowrap);
7575
final listData = listTree.listData;
7676
final listStyleType = itemTree.itemStyleType ?? listTree.listStyleType;
7777
final index = listData.markerReversed

packages/core/lib/src/internal/ops/tag_ruby.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension TagRuby on WidgetFactory {
3232
);
3333
break;
3434
case kTagRt:
35-
subTree.apply(TextStyleOps.fontSizeEm, .5);
35+
subTree.styleBuilder.enqueue(TextStyleOps.fontSizeEm, .5);
3636
break;
3737
}
3838
}

packages/core/test/src/data/build_bits_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class _BuildBitWidgetFactory extends WidgetFactory {
316316
}
317317

318318
if (classes.contains('custom')) {
319-
tree.apply((style, _) => style.copyWith(), null);
319+
tree.styleBuilder.enqueue((style, _) => style.copyWith(), null);
320320
}
321321

322322
super.parse(tree);

0 commit comments

Comments
 (0)