Add null check in TextStyle.apply for TextBaseline (#54442)
diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart
index 7683718..b2f9a3f 100644
--- a/packages/flutter/lib/src/painting/text_style.dart
+++ b/packages/flutter/lib/src/painting/text_style.dart
@@ -842,7 +842,7 @@
fontStyle: fontStyle ?? this.fontStyle,
letterSpacing: letterSpacing == null ? null : letterSpacing * letterSpacingFactor + letterSpacingDelta,
wordSpacing: wordSpacing == null ? null : wordSpacing * wordSpacingFactor + wordSpacingDelta,
- textBaseline: textBaseline,
+ textBaseline: textBaseline ?? this.textBaseline,
height: height == null ? null : height * heightFactor + heightDelta,
locale: locale ?? this.locale,
foreground: foreground,
diff --git a/packages/flutter/test/painting/text_style_test.dart b/packages/flutter/test/painting/text_style_test.dart
index 021b553..cabc633 100644
--- a/packages/flutter/test/painting/text_style_test.dart
+++ b/packages/flutter/test/painting/text_style_test.dart
@@ -374,14 +374,16 @@
});
test('TextStyle apply', () {
- const TextStyle style = TextStyle(fontSize: 10);
- expect(style.apply().shadows, isNull);
+ const TextStyle style = TextStyle(fontSize: 10, shadows: <ui.Shadow>[], fontStyle: FontStyle.normal, fontFeatures: <ui.FontFeature>[], textBaseline: TextBaseline.alphabetic);
+ expect(style.apply().shadows, const <ui.Shadow>[]);
expect(style.apply(shadows: const <ui.Shadow>[ui.Shadow(blurRadius: 2.0)]).shadows, const <ui.Shadow>[ui.Shadow(blurRadius: 2.0)]);
- expect(style.apply().fontStyle, isNull);
+ expect(style.apply().fontStyle, FontStyle.normal);
expect(style.apply(fontStyle: FontStyle.italic).fontStyle, FontStyle.italic);
expect(style.apply().locale, isNull);
expect(style.apply(locale: const Locale.fromSubtags(languageCode: 'es')).locale, const Locale.fromSubtags(languageCode: 'es'));
- expect(style.apply().fontFeatures, isNull);
+ expect(style.apply().fontFeatures, const <ui.FontFeature>[]);
expect(style.apply(fontFeatures: const <ui.FontFeature>[ui.FontFeature.enable('test')]).fontFeatures, const <ui.FontFeature>[ui.FontFeature.enable('test')]);
+ expect(style.apply().textBaseline, TextBaseline.alphabetic);
+ expect(style.apply(textBaseline: TextBaseline.ideographic).textBaseline, TextBaseline.ideographic);
});
}