Unverified Commit 812e0387 authored by Darren Austin's avatar Darren Austin Committed by GitHub

TextStyle.fontFamily should override fontFamily parameter in ThemeData constructor. (#42366)

Also updated the documentation for the ThemeData constructor to include
descriptions of parameters that don't map to specific fields directly.
parent 29bfb11c
...@@ -182,6 +182,20 @@ class ThemeData extends Diagnosticable { ...@@ -182,6 +182,20 @@ class ThemeData extends Diagnosticable {
/// ([accentColorBrightness]), so that the right contrasting text /// ([accentColorBrightness]), so that the right contrasting text
/// color will be used over the accent color. /// color will be used over the accent color.
/// ///
/// Most of these parameters map to the [ThemeData] field with the same name,
/// all of which are described in more detail on the fields themselves. The
/// exceptions are:
///
/// * [primarySwatch] - used to configure default values for several fields,
/// including: [primaryColor], [primaryColorBrightness], [primaryColorLight],
/// [primaryColorDark], [toggleableActiveColor], [accentColor], [colorScheme],
/// [secondaryHeaderColor], [textSelectionColor], [backgroundColor], and
/// [buttonColor].
///
/// * [fontFamily] - sets the default fontFamily for any
/// [TextStyle.fontFamily] that isn't set directly in the [textTheme],
/// [primaryTextTheme], or [accentTextTheme].
///
/// See <https://material.io/design/color/> for /// See <https://material.io/design/color/> for
/// more discussion on how to pick the right colors. /// more discussion on how to pick the right colors.
factory ThemeData({ factory ThemeData({
...@@ -301,19 +315,19 @@ class ThemeData extends Diagnosticable { ...@@ -301,19 +315,19 @@ class ThemeData extends Diagnosticable {
iconTheme ??= isDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black87); iconTheme ??= isDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black87);
platform ??= defaultTargetPlatform; platform ??= defaultTargetPlatform;
typography ??= Typography(platform: platform); typography ??= Typography(platform: platform);
final TextTheme defaultTextTheme = isDark ? typography.white : typography.black; TextTheme defaultTextTheme = isDark ? typography.white : typography.black;
TextTheme defaultPrimaryTextTheme = primaryIsDark ? typography.white : typography.black;
TextTheme defaultAccentTextTheme = accentIsDark ? typography.white : typography.black;
if (fontFamily != null) {
defaultTextTheme = defaultTextTheme.apply(fontFamily: fontFamily);
defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(fontFamily: fontFamily);
defaultAccentTextTheme = defaultAccentTextTheme.apply(fontFamily: fontFamily);
}
textTheme = defaultTextTheme.merge(textTheme); textTheme = defaultTextTheme.merge(textTheme);
final TextTheme defaultPrimaryTextTheme = primaryIsDark ? typography.white : typography.black;
primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme); primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme);
final TextTheme defaultAccentTextTheme = accentIsDark ? typography.white : typography.black;
accentTextTheme = defaultAccentTextTheme.merge(accentTextTheme); accentTextTheme = defaultAccentTextTheme.merge(accentTextTheme);
materialTapTargetSize ??= MaterialTapTargetSize.padded; materialTapTargetSize ??= MaterialTapTargetSize.padded;
applyElevationOverlayColor ??= false; applyElevationOverlayColor ??= false;
if (fontFamily != null) {
textTheme = textTheme.apply(fontFamily: fontFamily);
primaryTextTheme = primaryTextTheme.apply(fontFamily: fontFamily);
accentTextTheme = accentTextTheme.apply(fontFamily: fontFamily);
}
// Used as the default color (fill color) for RaisedButtons. Computing the // Used as the default color (fill color) for RaisedButtons. Computing the
// default for ButtonThemeData for the sake of backwards compatibility. // default for ButtonThemeData for the sake of backwards compatibility.
......
...@@ -99,12 +99,20 @@ void main() { ...@@ -99,12 +99,20 @@ void main() {
expect(themeData.materialTapTargetSize, MaterialTapTargetSize.padded); expect(themeData.materialTapTargetSize, MaterialTapTargetSize.padded);
}); });
test('Can control fontFamily', () { test('Can control fontFamily default', () {
final ThemeData themeData = ThemeData(fontFamily: 'Ahem'); final ThemeData themeData = ThemeData(
fontFamily: 'Ahem',
textTheme: const TextTheme(
title: TextStyle(fontFamily: 'Roboto'),
),
);
expect(themeData.textTheme.body2.fontFamily, equals('Ahem')); expect(themeData.textTheme.body2.fontFamily, equals('Ahem'));
expect(themeData.primaryTextTheme.title.fontFamily, equals('Ahem')); expect(themeData.primaryTextTheme.display2.fontFamily, equals('Ahem'));
expect(themeData.accentTextTheme.display4.fontFamily, equals('Ahem')); expect(themeData.accentTextTheme.display4.fontFamily, equals('Ahem'));
// Shouldn't override the specified style's family
expect(themeData.textTheme.title.fontFamily, equals('Roboto'));
}); });
test('Can estimate brightness - directly', () { test('Can estimate brightness - directly', () {
......
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