Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add fontFamily to ThemeData constructor #9016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/flutter/lib/src/material/theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class ThemeData {
Color indicatorColor,
Color hintColor,
Color errorColor,
String fontFamily,
TextTheme textTheme,
TextTheme primaryTextTheme,
TextTheme accentTextTheme,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions packages/flutter/test/material/theme_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}