From 59b2c5a39ef76eaf840fd86ac9d3aa81ee3d0fd9 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Fri, 10 Apr 2020 16:50:02 -0700 Subject: [PATCH] Add null check in TextStyle.apply for TextBaseline (#54442) --- packages/flutter/lib/src/painting/text_style.dart | 2 +- packages/flutter/test/painting/text_style_test.dart | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart index 7683718831..b2f9a3fb6c 100644 --- a/packages/flutter/lib/src/painting/text_style.dart +++ b/packages/flutter/lib/src/painting/text_style.dart @@ -842,7 +842,7 @@ class TextStyle with Diagnosticable { 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 021b55375f..cabc6331a0 100644 --- a/packages/flutter/test/painting/text_style_test.dart +++ b/packages/flutter/test/painting/text_style_test.dart @@ -374,14 +374,16 @@ void main() { }); test('TextStyle apply', () { - const TextStyle style = TextStyle(fontSize: 10); - expect(style.apply().shadows, isNull); + const TextStyle style = TextStyle(fontSize: 10, shadows: [], fontStyle: FontStyle.normal, fontFeatures: [], textBaseline: TextBaseline.alphabetic); + expect(style.apply().shadows, const []); expect(style.apply(shadows: const [ui.Shadow(blurRadius: 2.0)]).shadows, const [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 []); expect(style.apply(fontFeatures: const [ui.FontFeature.enable('test')]).fontFeatures, const [ui.FontFeature.enable('test')]); + expect(style.apply().textBaseline, TextBaseline.alphabetic); + expect(style.apply(textBaseline: TextBaseline.ideographic).textBaseline, TextBaseline.ideographic); }); }