Commit dccccb9b authored by Adam Barth's avatar Adam Barth Committed by GitHub

Add fontFamily to ThemeData constructor (#9016)

Otherwise it's somewhat verbose to configure all the text themes.
parent f8cf576f
...@@ -93,6 +93,7 @@ class ThemeData { ...@@ -93,6 +93,7 @@ class ThemeData {
Color indicatorColor, Color indicatorColor,
Color hintColor, Color hintColor,
Color errorColor, Color errorColor,
String fontFamily,
TextTheme textTheme, TextTheme textTheme,
TextTheme primaryTextTheme, TextTheme primaryTextTheme,
TextTheme accentTextTheme, TextTheme accentTextTheme,
...@@ -137,6 +138,11 @@ class ThemeData { ...@@ -137,6 +138,11 @@ class ThemeData {
textTheme ??= isDark ? typography.white : typography.black; textTheme ??= isDark ? typography.white : typography.black;
primaryTextTheme ??= primaryIsDark ? typography.white : typography.black; primaryTextTheme ??= primaryIsDark ? typography.white : typography.black;
accentTextTheme ??= accentIsDark ? 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( return new ThemeData.raw(
brightness: brightness, brightness: brightness,
primaryColor: primaryColor, primaryColor: primaryColor,
......
...@@ -81,4 +81,12 @@ void main() { ...@@ -81,4 +81,12 @@ void main() {
expect(lightTheme.accentTextTheme.title.color, typography.black.title.color); expect(lightTheme.accentTextTheme.title.color, typography.black.title.color);
expect(darkTheme.accentTextTheme.title.color, typography.white.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'));
});
} }
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