Skip to content

Commit 59b2c5a

Browse files
authored
Add null check in TextStyle.apply for TextBaseline (flutter#54442)
1 parent f7ee7ae commit 59b2c5a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/flutter/lib/src/painting/text_style.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ class TextStyle with Diagnosticable {
842842
fontStyle: fontStyle ?? this.fontStyle,
843843
letterSpacing: letterSpacing == null ? null : letterSpacing * letterSpacingFactor + letterSpacingDelta,
844844
wordSpacing: wordSpacing == null ? null : wordSpacing * wordSpacingFactor + wordSpacingDelta,
845-
textBaseline: textBaseline,
845+
textBaseline: textBaseline ?? this.textBaseline,
846846
height: height == null ? null : height * heightFactor + heightDelta,
847847
locale: locale ?? this.locale,
848848
foreground: foreground,

packages/flutter/test/painting/text_style_test.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,16 @@ void main() {
374374
});
375375

376376
test('TextStyle apply', () {
377-
const TextStyle style = TextStyle(fontSize: 10);
378-
expect(style.apply().shadows, isNull);
377+
const TextStyle style = TextStyle(fontSize: 10, shadows: <ui.Shadow>[], fontStyle: FontStyle.normal, fontFeatures: <ui.FontFeature>[], textBaseline: TextBaseline.alphabetic);
378+
expect(style.apply().shadows, const <ui.Shadow>[]);
379379
expect(style.apply(shadows: const <ui.Shadow>[ui.Shadow(blurRadius: 2.0)]).shadows, const <ui.Shadow>[ui.Shadow(blurRadius: 2.0)]);
380-
expect(style.apply().fontStyle, isNull);
380+
expect(style.apply().fontStyle, FontStyle.normal);
381381
expect(style.apply(fontStyle: FontStyle.italic).fontStyle, FontStyle.italic);
382382
expect(style.apply().locale, isNull);
383383
expect(style.apply(locale: const Locale.fromSubtags(languageCode: 'es')).locale, const Locale.fromSubtags(languageCode: 'es'));
384-
expect(style.apply().fontFeatures, isNull);
384+
expect(style.apply().fontFeatures, const <ui.FontFeature>[]);
385385
expect(style.apply(fontFeatures: const <ui.FontFeature>[ui.FontFeature.enable('test')]).fontFeatures, const <ui.FontFeature>[ui.FontFeature.enable('test')]);
386+
expect(style.apply().textBaseline, TextBaseline.alphabetic);
387+
expect(style.apply(textBaseline: TextBaseline.ideographic).textBaseline, TextBaseline.ideographic);
386388
});
387389
}

0 commit comments

Comments
 (0)