Add fontFamily to ThemeData constructor (#9016)

Otherwise it's somewhat verbose to configure all the text themes.
This commit is contained in:
Adam Barth
2017-03-26 10:53:02 -07:00
committed by GitHub
parent f8cf576f2b
commit dccccb9b82
2 changed files with 14 additions and 0 deletions

View File

@@ -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,

View File

@@ -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'));
});
}