Unverified Commit 4c6251a8 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Add fontFamilyFallback to ThemeData (#112976)

Add missing parameters to ThemeData (fontFamilyFallback and package)
parent 025a3ab3
...@@ -616,6 +616,8 @@ class TextTheme with Diagnosticable { ...@@ -616,6 +616,8 @@ class TextTheme with Diagnosticable {
/// point. /// point.
TextTheme apply({ TextTheme apply({
String? fontFamily, String? fontFamily,
List<String>? fontFamilyFallback,
String? package,
double fontSizeFactor = 1.0, double fontSizeFactor = 1.0,
double fontSizeDelta = 0.0, double fontSizeDelta = 0.0,
Color? displayColor, Color? displayColor,
...@@ -631,8 +633,10 @@ class TextTheme with Diagnosticable { ...@@ -631,8 +633,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
displayMedium: displayMedium?.apply( displayMedium: displayMedium?.apply(
color: displayColor, color: displayColor,
...@@ -640,8 +644,10 @@ class TextTheme with Diagnosticable { ...@@ -640,8 +644,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
displaySmall: displaySmall?.apply( displaySmall: displaySmall?.apply(
color: displayColor, color: displayColor,
...@@ -649,8 +655,10 @@ class TextTheme with Diagnosticable { ...@@ -649,8 +655,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
headlineLarge: headlineLarge?.apply( headlineLarge: headlineLarge?.apply(
color: displayColor, color: displayColor,
...@@ -658,8 +666,10 @@ class TextTheme with Diagnosticable { ...@@ -658,8 +666,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
headlineMedium: headlineMedium?.apply( headlineMedium: headlineMedium?.apply(
color: displayColor, color: displayColor,
...@@ -667,8 +677,10 @@ class TextTheme with Diagnosticable { ...@@ -667,8 +677,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
headlineSmall: headlineSmall?.apply( headlineSmall: headlineSmall?.apply(
color: bodyColor, color: bodyColor,
...@@ -676,8 +688,10 @@ class TextTheme with Diagnosticable { ...@@ -676,8 +688,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
titleLarge: titleLarge?.apply( titleLarge: titleLarge?.apply(
color: bodyColor, color: bodyColor,
...@@ -685,8 +699,10 @@ class TextTheme with Diagnosticable { ...@@ -685,8 +699,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
titleMedium: titleMedium?.apply( titleMedium: titleMedium?.apply(
color: bodyColor, color: bodyColor,
...@@ -694,8 +710,10 @@ class TextTheme with Diagnosticable { ...@@ -694,8 +710,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
titleSmall: titleSmall?.apply( titleSmall: titleSmall?.apply(
color: bodyColor, color: bodyColor,
...@@ -703,8 +721,10 @@ class TextTheme with Diagnosticable { ...@@ -703,8 +721,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
bodyLarge: bodyLarge?.apply( bodyLarge: bodyLarge?.apply(
color: bodyColor, color: bodyColor,
...@@ -712,8 +732,10 @@ class TextTheme with Diagnosticable { ...@@ -712,8 +732,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
bodyMedium: bodyMedium?.apply( bodyMedium: bodyMedium?.apply(
color: bodyColor, color: bodyColor,
...@@ -721,8 +743,10 @@ class TextTheme with Diagnosticable { ...@@ -721,8 +743,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
bodySmall: bodySmall?.apply( bodySmall: bodySmall?.apply(
color: displayColor, color: displayColor,
...@@ -730,8 +754,10 @@ class TextTheme with Diagnosticable { ...@@ -730,8 +754,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
labelLarge: labelLarge?.apply( labelLarge: labelLarge?.apply(
color: bodyColor, color: bodyColor,
...@@ -739,8 +765,10 @@ class TextTheme with Diagnosticable { ...@@ -739,8 +765,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
labelMedium: labelMedium?.apply( labelMedium: labelMedium?.apply(
color: bodyColor, color: bodyColor,
...@@ -748,8 +776,10 @@ class TextTheme with Diagnosticable { ...@@ -748,8 +776,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
labelSmall: labelSmall?.apply( labelSmall: labelSmall?.apply(
color: bodyColor, color: bodyColor,
...@@ -757,8 +787,10 @@ class TextTheme with Diagnosticable { ...@@ -757,8 +787,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor, decorationColor: decorationColor,
decorationStyle: decorationStyle, decorationStyle: decorationStyle,
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor, fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta, fontSizeDelta: fontSizeDelta,
package: package,
), ),
); );
} }
......
...@@ -322,6 +322,8 @@ class ThemeData with Diagnosticable { ...@@ -322,6 +322,8 @@ class ThemeData with Diagnosticable {
Color? unselectedWidgetColor, Color? unselectedWidgetColor,
// TYPOGRAPHY & ICONOGRAPHY // TYPOGRAPHY & ICONOGRAPHY
String? fontFamily, String? fontFamily,
List<String>? fontFamilyFallback,
String? package,
IconThemeData? iconTheme, IconThemeData? iconTheme,
IconThemeData? primaryIconTheme, IconThemeData? primaryIconTheme,
TextTheme? primaryTextTheme, TextTheme? primaryTextTheme,
...@@ -561,6 +563,16 @@ class ThemeData with Diagnosticable { ...@@ -561,6 +563,16 @@ class ThemeData with Diagnosticable {
defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(fontFamily: fontFamily); defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(fontFamily: fontFamily);
defaultAccentTextTheme = defaultAccentTextTheme.apply(fontFamily: fontFamily); defaultAccentTextTheme = defaultAccentTextTheme.apply(fontFamily: fontFamily);
} }
if (fontFamilyFallback != null) {
defaultTextTheme = defaultTextTheme.apply(fontFamilyFallback: fontFamilyFallback);
defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(fontFamilyFallback: fontFamilyFallback);
defaultAccentTextTheme = defaultAccentTextTheme.apply(fontFamilyFallback: fontFamilyFallback);
}
if (package != null) {
defaultTextTheme = defaultTextTheme.apply(package: package);
defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(package: package);
defaultAccentTextTheme = defaultAccentTextTheme.apply(package: package);
}
textTheme = defaultTextTheme.merge(textTheme); textTheme = defaultTextTheme.merge(textTheme);
primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme); primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme);
iconTheme ??= isDark ? const IconThemeData(color: kDefaultIconLightColor) : const IconThemeData(color: kDefaultIconDarkColor); iconTheme ??= isDark ? const IconThemeData(color: kDefaultIconLightColor) : const IconThemeData(color: kDefaultIconDarkColor);
......
...@@ -79,6 +79,7 @@ void main() { ...@@ -79,6 +79,7 @@ void main() {
const Color displayColor = Color(0x00000001); const Color displayColor = Color(0x00000001);
const Color bodyColor = Color(0x00000002); const Color bodyColor = Color(0x00000002);
const String fontFamily = 'fontFamily'; const String fontFamily = 'fontFamily';
const List<String> fontFamilyFallback = <String>['font', 'family', 'fallback'];
const Color decorationColor = Color(0x00000003); const Color decorationColor = Color(0x00000003);
const TextDecorationStyle decorationStyle = TextDecorationStyle.dashed; const TextDecorationStyle decorationStyle = TextDecorationStyle.dashed;
final TextDecoration decoration = TextDecoration.combine(<TextDecoration>[ final TextDecoration decoration = TextDecoration.combine(<TextDecoration>[
...@@ -89,6 +90,7 @@ void main() { ...@@ -89,6 +90,7 @@ void main() {
final Typography typography = Typography.material2018(); final Typography typography = Typography.material2018();
final TextTheme theme = typography.black.apply( final TextTheme theme = typography.black.apply(
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
displayColor: displayColor, displayColor: displayColor,
bodyColor: bodyColor, bodyColor: bodyColor,
decoration: decoration, decoration: decoration,
...@@ -130,6 +132,7 @@ void main() { ...@@ -130,6 +132,7 @@ void main() {
theme.labelSmall!, theme.labelSmall!,
]; ];
expect(themeStyles.every((TextStyle style) => style.fontFamily == fontFamily), true); expect(themeStyles.every((TextStyle style) => style.fontFamily == fontFamily), true);
expect(themeStyles.every((TextStyle style) => style.fontFamilyFallback == fontFamilyFallback), true);
expect(themeStyles.every((TextStyle style) => style.decorationColor == decorationColor), true); expect(themeStyles.every((TextStyle style) => style.decorationColor == decorationColor), true);
expect(themeStyles.every((TextStyle style) => style.decorationStyle == decorationStyle), true); expect(themeStyles.every((TextStyle style) => style.decorationStyle == decorationStyle), true);
expect(themeStyles.every((TextStyle style) => style.decoration == decoration), true); expect(themeStyles.every((TextStyle style) => style.decoration == decoration), true);
......
...@@ -865,6 +865,39 @@ void main() { ...@@ -865,6 +865,39 @@ void main() {
semantics.dispose(); semantics.dispose();
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/62945 }, skip: isBrowser); // https://github.com/flutter/flutter/issues/62945
testWidgets('receives fontFamilyFallback and package from root ThemeData', (WidgetTester tester) async {
const String fontFamily = 'fontFamily';
const String package = 'package_name';
final List<String> fontFamilyFallback = <String>['font', 'family', 'fallback'];
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
package: package,
primarySwatch: Colors.blue,
),
home: const Scaffold(
body: Center(
child: Text(
'foo',
),
),
),
),
);
expect(find.byType(RichText), findsOneWidget);
final RichText richText = tester.widget(find.byType(RichText));
final InlineSpan text = richText.text;
final TextStyle? style = text.style;
expect(style?.fontFamily, equals('packages/$package/$fontFamily'));
for (int i = 0; i < fontFamilyFallback.length; i++) {
final String fallback = fontFamilyFallback[i];
expect(style?.fontFamilyFallback?[i], equals('packages/$package/$fallback'));
}
});
testWidgets('Overflow is clipping correctly - short text with overflow: clip', (WidgetTester tester) async { testWidgets('Overflow is clipping correctly - short text with overflow: clip', (WidgetTester tester) async {
await _pumpTextWidget( await _pumpTextWidget(
tester: tester, tester: tester,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment