Add fontFamily to ThemeData constructor (#9016)
Otherwise it's somewhat verbose to configure all the text themes.
This commit is contained in:
@@ -93,6 +93,7 @@ class ThemeData {
|
||||
Color indicatorColor,
|
||||
Color hintColor,
|
||||
Color errorColor,
|
||||
String fontFamily,
|
||||
TextTheme textTheme,
|
||||
TextTheme primaryTextTheme,
|
||||
TextTheme accentTextTheme,
|
||||
@@ -137,6 +138,11 @@ class ThemeData {
|
||||
textTheme ??= isDark ? typography.white : typography.black;
|
||||
primaryTextTheme ??= primaryIsDark ? typography.white : typography.black;
|
||||
accentTextTheme ??= accentIsDark ? typography.white : typography.black;
|
||||
if (fontFamily != null) {
|
||||
textTheme = textTheme.apply(fontFamily: fontFamily);
|
||||
primaryTextTheme = primaryTextTheme.apply(fontFamily: fontFamily);
|
||||
accentTextTheme = accentTextTheme.apply(fontFamily: fontFamily);
|
||||
}
|
||||
return new ThemeData.raw(
|
||||
brightness: brightness,
|
||||
primaryColor: primaryColor,
|
||||
|
||||
@@ -81,4 +81,12 @@ void main() {
|
||||
expect(lightTheme.accentTextTheme.title.color, typography.black.title.color);
|
||||
expect(darkTheme.accentTextTheme.title.color, typography.white.title.color);
|
||||
});
|
||||
|
||||
test('Can control fontFamily', () {
|
||||
final ThemeData themeData = new ThemeData(fontFamily: 'Ahem');
|
||||
|
||||
expect(themeData.textTheme.body2.fontFamily, equals('Ahem'));
|
||||
expect(themeData.primaryTextTheme.title.fontFamily, equals('Ahem'));
|
||||
expect(themeData.accentTextTheme.display4.fontFamily, equals('Ahem'));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user