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 {
/// point.
TextTheme apply({
String? fontFamily,
List<String>? fontFamilyFallback,
String? package,
double fontSizeFactor = 1.0,
double fontSizeDelta = 0.0,
Color? displayColor,
......@@ -631,8 +633,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
displayMedium: displayMedium?.apply(
color: displayColor,
......@@ -640,8 +644,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
displaySmall: displaySmall?.apply(
color: displayColor,
......@@ -649,8 +655,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
headlineLarge: headlineLarge?.apply(
color: displayColor,
......@@ -658,8 +666,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
headlineMedium: headlineMedium?.apply(
color: displayColor,
......@@ -667,8 +677,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
headlineSmall: headlineSmall?.apply(
color: bodyColor,
......@@ -676,8 +688,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
titleLarge: titleLarge?.apply(
color: bodyColor,
......@@ -685,8 +699,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
titleMedium: titleMedium?.apply(
color: bodyColor,
......@@ -694,8 +710,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
titleSmall: titleSmall?.apply(
color: bodyColor,
......@@ -703,8 +721,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
bodyLarge: bodyLarge?.apply(
color: bodyColor,
......@@ -712,8 +732,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
bodyMedium: bodyMedium?.apply(
color: bodyColor,
......@@ -721,8 +743,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
bodySmall: bodySmall?.apply(
color: displayColor,
......@@ -730,8 +754,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
labelLarge: labelLarge?.apply(
color: bodyColor,
......@@ -739,8 +765,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
labelMedium: labelMedium?.apply(
color: bodyColor,
......@@ -748,8 +776,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
labelSmall: labelSmall?.apply(
color: bodyColor,
......@@ -757,8 +787,10 @@ class TextTheme with Diagnosticable {
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSizeFactor: fontSizeFactor,
fontSizeDelta: fontSizeDelta,
package: package,
),
);
}
......
......@@ -322,6 +322,8 @@ class ThemeData with Diagnosticable {
Color? unselectedWidgetColor,
// TYPOGRAPHY & ICONOGRAPHY
String? fontFamily,
List<String>? fontFamilyFallback,
String? package,
IconThemeData? iconTheme,
IconThemeData? primaryIconTheme,
TextTheme? primaryTextTheme,
......@@ -561,6 +563,16 @@ class ThemeData with Diagnosticable {
defaultPrimaryTextTheme = defaultPrimaryTextTheme.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);
primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme);
iconTheme ??= isDark ? const IconThemeData(color: kDefaultIconLightColor) : const IconThemeData(color: kDefaultIconDarkColor);
......
......@@ -79,6 +79,7 @@ void main() {
const Color displayColor = Color(0x00000001);
const Color bodyColor = Color(0x00000002);
const String fontFamily = 'fontFamily';
const List<String> fontFamilyFallback = <String>['font', 'family', 'fallback'];
const Color decorationColor = Color(0x00000003);
const TextDecorationStyle decorationStyle = TextDecorationStyle.dashed;
final TextDecoration decoration = TextDecoration.combine(<TextDecoration>[
......@@ -89,6 +90,7 @@ void main() {
final Typography typography = Typography.material2018();
final TextTheme theme = typography.black.apply(
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
displayColor: displayColor,
bodyColor: bodyColor,
decoration: decoration,
......@@ -130,6 +132,7 @@ void main() {
theme.labelSmall!,
];
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.decorationStyle == decorationStyle), true);
expect(themeStyles.every((TextStyle style) => style.decoration == decoration), true);
......
......@@ -865,6 +865,39 @@ void main() {
semantics.dispose();
}, 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 {
await _pumpTextWidget(
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