From 356a98184e131eed39b10839d51ed8703fb57695 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Sun, 26 Mar 2017 10:45:30 -0700 Subject: [PATCH] Add fontFamily to ThemeData constructor Otherwise it's somewhat verbose to configure all the text themes. --- packages/flutter/lib/src/material/theme_data.dart | 6 ++++++ packages/flutter/test/material/theme_data_test.dart | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index 0aead08035aff..76e21b6bda6ca 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -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, diff --git a/packages/flutter/test/material/theme_data_test.dart b/packages/flutter/test/material/theme_data_test.dart index 58d439ccac61a..77ac506d5c5b3 100644 --- a/packages/flutter/test/material/theme_data_test.dart +++ b/packages/flutter/test/material/theme_data_test.dart @@ -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')); + }); }