From 19ff596979e407c484a32f4071420fca4f4c885f Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 8 Apr 2020 15:42:02 -0700 Subject: [PATCH] Add missing properties to TextStyle.apply (#54305) --- .../flutter/lib/src/painting/text_style.dart | 13 +++++++++---- packages/flutter/test/material/theme_test.dart | 5 +++++ .../flutter/test/painting/text_style_test.dart | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart index eec3589ba5..7683718831 100644 --- a/packages/flutter/lib/src/painting/text_style.dart +++ b/packages/flutter/lib/src/painting/text_style.dart @@ -794,12 +794,17 @@ class TextStyle with Diagnosticable { double fontSizeFactor = 1.0, double fontSizeDelta = 0.0, int fontWeightDelta = 0, + FontStyle fontStyle, double letterSpacingFactor = 1.0, double letterSpacingDelta = 0.0, double wordSpacingFactor = 1.0, double wordSpacingDelta = 0.0, double heightFactor = 1.0, double heightDelta = 0.0, + TextBaseline textBaseline, + Locale locale, + List shadows, + List fontFeatures, }) { assert(fontSizeFactor != null); assert(fontSizeDelta != null); @@ -834,16 +839,16 @@ class TextStyle with Diagnosticable { fontFamilyFallback: fontFamilyFallback ?? this.fontFamilyFallback, fontSize: fontSize == null ? null : fontSize * fontSizeFactor + fontSizeDelta, fontWeight: fontWeight == null ? null : FontWeight.values[(fontWeight.index + fontWeightDelta).clamp(0, FontWeight.values.length - 1) as int], - fontStyle: fontStyle, + fontStyle: fontStyle ?? this.fontStyle, letterSpacing: letterSpacing == null ? null : letterSpacing * letterSpacingFactor + letterSpacingDelta, wordSpacing: wordSpacing == null ? null : wordSpacing * wordSpacingFactor + wordSpacingDelta, textBaseline: textBaseline, height: height == null ? null : height * heightFactor + heightDelta, - locale: locale, + locale: locale ?? this.locale, foreground: foreground, background: background, - shadows: shadows, - fontFeatures: fontFeatures, + shadows: shadows ?? this.shadows, + fontFeatures: fontFeatures ?? this.fontFeatures, decoration: decoration ?? this.decoration, decorationColor: decorationColor ?? this.decorationColor, decorationStyle: decorationStyle ?? this.decorationStyle, diff --git a/packages/flutter/test/material/theme_test.dart b/packages/flutter/test/material/theme_test.dart index 941444d5f3..8835aa439a 100644 --- a/packages/flutter/test/material/theme_test.dart +++ b/packages/flutter/test/material/theme_test.dart @@ -774,12 +774,17 @@ class _TextStyleProxy implements TextStyle { double fontSizeFactor = 1.0, double fontSizeDelta = 0.0, int fontWeightDelta = 0, + FontStyle fontStyle, double letterSpacingFactor = 1.0, double letterSpacingDelta = 0.0, double wordSpacingFactor = 1.0, double wordSpacingDelta = 0.0, double heightFactor = 1.0, double heightDelta = 0.0, + TextBaseline textBaseline, + Locale locale, + List shadows, + List fontFeatures, }) { throw UnimplementedError(); } diff --git a/packages/flutter/test/painting/text_style_test.dart b/packages/flutter/test/painting/text_style_test.dart index d3722e257c..021b55375f 100644 --- a/packages/flutter/test/painting/text_style_test.dart +++ b/packages/flutter/test/painting/text_style_test.dart @@ -233,6 +233,11 @@ void main() { final ui.TextStyle uis1 = s2.getTextStyle(); expect(uis1.toString(), 'TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, decorationThickness: unspecified, fontWeight: unspecified, fontStyle: unspecified, textBaseline: unspecified, fontFamily: foo, fontFamilyFallback: [Roboto, test], fontSize: unspecified, letterSpacing: unspecified, wordSpacing: unspecified, height: unspecified, locale: unspecified, background: unspecified, foreground: unspecified, shadows: unspecified, fontFeatures: unspecified)'); + + expect(s2.apply().fontFamily, 'foo'); + expect(s2.apply().fontFamilyFallback, const ['Roboto', 'test']); + expect(s2.apply(fontFamily: 'bar').fontFamily, 'bar'); + expect(s2.apply(fontFamilyFallback: const ['Banana']).fontFamilyFallback, const ['Banana']); }, skip: isBrowser); test('TextStyle.debugLabel', () { @@ -367,4 +372,16 @@ void main() { expect(paragraphStyle0 == paragraphStyle1, true); }); + + test('TextStyle apply', () { + const TextStyle style = TextStyle(fontSize: 10); + expect(style.apply().shadows, isNull); + 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.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.enable('test')]).fontFeatures, const [ui.FontFeature.enable('test')]); + }); }