Skip to content

Commit 14c8c24

Browse files
authored
[web] Fix regression in foreground style (flutter#22999)
1 parent 6ebf5c3 commit 14c8c24

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/web_ui/lib/src/engine/text/paragraph.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ class DomParagraphBuilder implements ui.ParagraphBuilder {
13281328
/// paragraph. Plain text is more efficient to lay out and measure than rich
13291329
/// text.
13301330
EngineParagraph? _tryBuildPlainText() {
1331-
ui.Color color = _defaultTextColor;
1331+
ui.Color? color;
13321332
ui.TextDecoration? decoration;
13331333
ui.Color? decorationColor;
13341334
ui.TextDecorationStyle? decorationStyle;
@@ -1416,6 +1416,10 @@ class DomParagraphBuilder implements ui.ParagraphBuilder {
14161416
i++;
14171417
}
14181418

1419+
if (color == null && foreground == null) {
1420+
color = _defaultTextColor;
1421+
}
1422+
14191423
final EngineTextStyle cumulativeStyle = EngineTextStyle(
14201424
color: color,
14211425
decoration: decoration,
@@ -1443,7 +1447,7 @@ class DomParagraphBuilder implements ui.ParagraphBuilder {
14431447
paint = foreground;
14441448
} else {
14451449
paint = ui.Paint();
1446-
paint.color = color;
1450+
paint.color = color!;
14471451
}
14481452

14491453
if (i >= _ops.length) {

lib/web_ui/test/paragraph_builder_test.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.6
5+
// @dart = 2.12
66
import 'package:test/bootstrap/browser.dart';
77
import 'package:test/test.dart';
88
import 'package:ui/src/engine.dart';
@@ -28,10 +28,20 @@ void testMain() {
2828
expect(paragraph.height, isNonZero);
2929
});
3030

31-
test('PushStyle should not segfault after build()', () {
31+
test('pushStyle should not segfault after build()', () {
3232
final ParagraphBuilder paragraphBuilder =
3333
ParagraphBuilder(ParagraphStyle());
3434
paragraphBuilder.build();
3535
paragraphBuilder.pushStyle(TextStyle());
3636
});
37+
38+
test('the presence of foreground style should not throw', () {
39+
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle());
40+
builder.pushStyle(TextStyle(
41+
foreground: Paint()..color = const Color(0xFFABCDEF),
42+
));
43+
builder.addText('hi');
44+
45+
expect(() => builder.build(), returnsNormally);
46+
});
3747
}

0 commit comments

Comments
 (0)