diff --git a/assets/fonts/DejaVuSans-Bold.ttf b/assets/fonts/DejaVuSans-Bold.ttf new file mode 100644 index 000000000..6d65fa7dc Binary files /dev/null and b/assets/fonts/DejaVuSans-Bold.ttf differ diff --git a/assets/fonts/DejaVuSans-ExtraLight.ttf b/assets/fonts/DejaVuSans-ExtraLight.ttf new file mode 100644 index 000000000..b09f32d7d Binary files /dev/null and b/assets/fonts/DejaVuSans-ExtraLight.ttf differ diff --git a/assets/fonts/DejaVuSans.ttf b/assets/fonts/DejaVuSans.ttf new file mode 100644 index 000000000..e5f7eecce Binary files /dev/null and b/assets/fonts/DejaVuSans.ttf differ diff --git a/lib/main.dart b/lib/main.dart index 99d4fcb7e..93a2a9b76 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -315,10 +315,13 @@ TextTheme _defaultTextTheme() { // This text theme is merged with the default theme in the `TextData` // constructor. This makes sure that the emoji font is used as fallback for // every text that uses the default theme. - var style; + + // Make sure this is the same as in lib/services/theme.dart ThemeService() + var fontFamilyFallback = ['NunitoSans', 'DejavuSans']; if (isOnDesktop) { - style = new TextStyle(fontFamilyFallback: ['Emoji']); + fontFamilyFallback = ['NunitoSans', 'Emoji', 'DejavuSans']; } + var style = new TextStyle(fontFamilyFallback: fontFamilyFallback); return new TextTheme( body1: style, body2: style, diff --git a/lib/pages/home/modals/create_post/widgets/create_post_text.dart b/lib/pages/home/modals/create_post/widgets/create_post_text.dart index 89ccc10cf..d62c8f64c 100644 --- a/lib/pages/home/modals/create_post/widgets/create_post_text.dart +++ b/lib/pages/home/modals/create_post/widgets/create_post_text.dart @@ -29,16 +29,15 @@ class OBCreatePostText extends StatelessWidget { textCapitalization: TextCapitalization.sentences, keyboardType: TextInputType.multiline, maxLines: null, - style: TextStyle( - color: themeValueParserService.parseColor(theme.primaryTextColor), - fontSize: 18.0), + style: themeService.getThemedTextStyle(theme).merge(TextStyle( + fontSize: 18.0)), decoration: InputDecoration( border: InputBorder.none, hintText: this.hintText != null ? this.hintText : 'What\'s going on?', - hintStyle: TextStyle( + hintStyle: themeService.getDefaultTextStyle().merge(TextStyle( color: themeValueParserService .parseColor(theme.secondaryTextColor), - fontSize: 18.0)), + fontSize: 18.0))), autocorrect: true, ); }); diff --git a/lib/pages/home/modals/create_post/widgets/remaining_post_characters.dart b/lib/pages/home/modals/create_post/widgets/remaining_post_characters.dart index 616d394ba..4451a3d2c 100644 --- a/lib/pages/home/modals/create_post/widgets/remaining_post_characters.dart +++ b/lib/pages/home/modals/create_post/widgets/remaining_post_characters.dart @@ -27,7 +27,7 @@ class OBRemainingPostCharacters extends StatelessWidget { return Text( remainingCharacters.toString(), - style: TextStyle( + style: themeService.getDefaultTextStyle().merge(TextStyle( fontSize: 12.0, color: exceededMaxCharacters ? themeValueParserService.parseColor(theme.dangerColor) @@ -35,7 +35,7 @@ class OBRemainingPostCharacters extends StatelessWidget { .parseColor(theme.primaryTextColor), fontWeight: exceededMaxCharacters ? FontWeight.bold - : FontWeight.normal), + : FontWeight.normal)), ); }); } diff --git a/lib/pages/home/pages/communities/widgets/user_avatar_tab.dart b/lib/pages/home/pages/communities/widgets/user_avatar_tab.dart index 0e203a9c6..688924279 100644 --- a/lib/pages/home/pages/communities/widgets/user_avatar_tab.dart +++ b/lib/pages/home/pages/communities/widgets/user_avatar_tab.dart @@ -6,6 +6,7 @@ import 'package:Okuna/services/theme_value_parser.dart'; import 'package:Okuna/widgets/alerts/alert.dart'; import 'package:Okuna/widgets/avatars/avatar.dart'; import 'package:Okuna/widgets/tabs/image_tab.dart'; +import 'package:Okuna/widgets/theming/text.dart'; import 'package:flutter/material.dart'; class OBUserAvatarTab extends StatelessWidget { @@ -53,7 +54,7 @@ class OBUserAvatarTab extends StatelessWidget { Radius.circular(OBImageTab.borderRadius), bottomRight: Radius.circular(OBImageTab.borderRadius))), - child: Text( + child: OBText( 'You', textAlign: TextAlign.center, style: TextStyle(color: Colors.white, fontSize: 16), diff --git a/lib/pages/home/widgets/bottom-tab-bar.dart b/lib/pages/home/widgets/bottom-tab-bar.dart index d9d17e634..fced74e45 100644 --- a/lib/pages/home/widgets/bottom-tab-bar.dart +++ b/lib/pages/home/widgets/bottom-tab-bar.dart @@ -124,13 +124,13 @@ class OBCupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { ), child: DefaultTextStyle( // Default with the inactive state. - style: TextStyle( + style: themeService.getDefaultTextStyle().merge(TextStyle( fontFamily: '.SF UI Text', fontSize: 10.0, letterSpacing: 0.1, fontWeight: FontWeight.w400, color: inactiveColor, - ), + )), child: Padding( padding: EdgeInsets.only(bottom: bottomPadding), child: Row( diff --git a/lib/provider.dart b/lib/provider.dart index 00184ca6f..912745c85 100644 --- a/lib/provider.dart +++ b/lib/provider.dart @@ -162,6 +162,7 @@ class OpenbookProviderState extends State { validationService .setConnectionsCirclesApiService(connectionsCirclesApiService); themeService.setStorageService(storageService); + themeService.setThemeValueParserService(themeValueParserService); pushNotificationsService.setUserService(userService); intercomService.setUserService(userService); dialogService.setThemeService(themeService); diff --git a/lib/services/theme.dart b/lib/services/theme.dart index 6e2006d60..070594fca 100644 --- a/lib/services/theme.dart +++ b/lib/services/theme.dart @@ -1,5 +1,8 @@ +import 'package:Okuna/main.dart'; import 'package:Okuna/models/theme.dart'; import 'package:Okuna/services/storage.dart'; +import 'package:Okuna/services/theme_value_parser.dart'; +import 'package:flutter/widgets.dart'; import 'package:rxdart/rxdart.dart'; import 'dart:math'; @@ -12,6 +15,9 @@ class ThemeService { OBTheme _activeTheme; OBStorage _storage; + ThemeValueParserService _themeValueParserService; + + TextStyle _defaultTextStyle; List _themes = [ OBTheme( @@ -172,6 +178,16 @@ class ThemeService { ThemeService() { _setActiveTheme(_themes[2]); + // Make sure this is the same as in lib/main.dart _getDefaultTextTheme() + var fontFamilyFallback = ['NunitoSans', 'DejaVuSans']; + if (isOnDesktop) { + fontFamilyFallback = ['NunitoSans', 'Emoji', 'DejaVuSans']; + } + _defaultTextStyle = TextStyle( + fontFamily: 'NunitoSans', + fontFamilyFallback: fontFamilyFallback, + fontStyle: FontStyle.normal, + fontWeight: FontWeight.normal); } void setStorageService(StorageService storageService) { @@ -179,6 +195,11 @@ class ThemeService { this._bootstrap(); } + void setThemeValueParserService( + ThemeValueParserService themeValueParserService) { + _themeValueParserService = themeValueParserService; + } + void setActiveTheme(OBTheme theme) { _setActiveTheme(theme); _storeActiveThemeId(theme.id); @@ -231,4 +252,17 @@ class ThemeService { while (length-- > 0) hex += chars[(random.nextInt(16)) | 0]; return hex; } + + TextStyle getDefaultTextStyle() { + return _defaultTextStyle; + } + + TextStyle getTextStyle(TextStyle custom) { + return _defaultTextStyle.merge(custom); + } + + TextStyle getThemedTextStyle(OBTheme theme) { + return getTextStyle(TextStyle( + color: _themeValueParserService.parseColor(theme.primaryTextColor))); + } } diff --git a/lib/widgets/badges/badge.dart b/lib/widgets/badges/badge.dart index 2a7e67ed4..a5b228869 100644 --- a/lib/widgets/badges/badge.dart +++ b/lib/widgets/badges/badge.dart @@ -31,14 +31,16 @@ class OBBadge extends StatelessWidget { gradient: primaryAccentColor, borderRadius: BorderRadius.circular(50)), child: Center( - child: count != null ? Text( - count.toString(), - style: TextStyle( - color: Colors.white, - fontSize: count < 10 ? 12 : 10, - fontWeight: FontWeight.bold), - ) : const SizedBox() - ), + child: count != null + ? Text( + count.toString(), + style: themeService.getDefaultTextStyle().merge( + TextStyle( + color: Colors.white, + fontSize: count < 10 ? 12 : 10, + fontWeight: FontWeight.bold)), + ) + : const SizedBox()), ); }); } diff --git a/lib/widgets/theming/primary_accent_text.dart b/lib/widgets/theming/primary_accent_text.dart index 239ed8bce..d0cbcc619 100644 --- a/lib/widgets/theming/primary_accent_text.dart +++ b/lib/widgets/theming/primary_accent_text.dart @@ -28,16 +28,15 @@ class OBPrimaryAccentText extends StatelessWidget { builder: (BuildContext context, AsyncSnapshot snapshot) { var theme = snapshot.data; - TextStyle finalStyle = style; - TextStyle themedTextStyle = TextStyle( - foreground: Paint() - ..shader = themeValueParserService - .parseGradient(theme.primaryAccentColor).createShader(Rect.fromLTWH(0.0, 0.0, 200.0, 70.0))); + TextStyle finalStyle = themeService.getDefaultTextStyle().merge( + TextStyle( + foreground: Paint() + ..shader = themeValueParserService + .parseGradient(theme.primaryAccentColor) + .createShader(Rect.fromLTWH(0.0, 0.0, 200.0, 70.0)))); - if (finalStyle != null) { - finalStyle = finalStyle.merge(themedTextStyle); - } else { - finalStyle = themedTextStyle; + if (style != null) { + finalStyle = style.merge(finalStyle); } return OBText( diff --git a/lib/widgets/theming/secondary_text.dart b/lib/widgets/theming/secondary_text.dart index 35036a29d..4359a9136 100644 --- a/lib/widgets/theming/secondary_text.dart +++ b/lib/widgets/theming/secondary_text.dart @@ -25,15 +25,13 @@ class OBSecondaryText extends StatelessWidget { builder: (BuildContext context, AsyncSnapshot snapshot) { var theme = snapshot.data; - TextStyle finalStyle = style; - TextStyle themedTextStyle = TextStyle( - color: - themeValueParserService.parseColor(theme.secondaryTextColor)); + TextStyle finalStyle = themeService.getDefaultTextStyle().merge( + TextStyle( + color: themeValueParserService + .parseColor(theme.secondaryTextColor))); - if (finalStyle != null) { - finalStyle = finalStyle.merge(themedTextStyle); - } else { - finalStyle = themedTextStyle; + if (style != null) { + finalStyle = style.merge(finalStyle); } return OBText( diff --git a/lib/widgets/theming/smart_text.dart b/lib/widgets/theming/smart_text.dart index a9d50d52a..4ddef5b5a 100644 --- a/lib/widgets/theming/smart_text.dart +++ b/lib/widgets/theming/smart_text.dart @@ -380,13 +380,9 @@ class OBSmartText extends StatelessWidget { builder: (BuildContext context, AsyncSnapshot snapshot) { OBTheme theme = snapshot.data; - Color primaryTextColor = - themeValueParserService.parseColor(theme.primaryTextColor); - - TextStyle textStyle = TextStyle( - color: primaryTextColor, - fontSize: fontSize, - fontFamilyFallback: ['NunitoSans']); + TextStyle textStyle = themeService + .getThemedTextStyle(theme) + .merge(TextStyle(fontSize: fontSize)); TextStyle secondaryTextStyle; @@ -395,21 +391,18 @@ class OBSmartText extends StatelessWidget { Color secondaryTextColor = themeValueParserService.parseColor(theme.secondaryTextColor); secondaryTextColor = TinyColor(secondaryTextColor).lighten(10).color; - secondaryTextStyle = TextStyle( - color: secondaryTextColor, - fontSize: fontSize * 0.8, - fontFamilyFallback: ['NunitoSans']); + secondaryTextStyle = textStyle.merge( + TextStyle(color: secondaryTextColor, fontSize: fontSize * 0.8)); } Color actionsForegroundColor = themeValueParserService .parseGradient(theme.primaryAccentColor) .colors[1]; - TextStyle smartItemsStyle = TextStyle( + TextStyle smartItemsStyle = textStyle.merge(TextStyle( color: actionsForegroundColor, - fontSize: fontSize, fontWeight: FontWeight.bold, - ); + )); return RichText( overflow: overflow, diff --git a/lib/widgets/theming/text.dart b/lib/widgets/theming/text.dart index d2a3a6cc4..58bbb729e 100644 --- a/lib/widgets/theming/text.dart +++ b/lib/widgets/theming/text.dart @@ -47,7 +47,6 @@ class OBText extends StatelessWidget { Widget build(BuildContext context) { var openbookProvider = OpenbookProvider.of(context); var themeService = openbookProvider.themeService; - var themeValueParserService = openbookProvider.themeValueParserService; double fontSize = getTextSize(size); @@ -57,12 +56,12 @@ class OBText extends StatelessWidget { builder: (BuildContext context, AsyncSnapshot snapshot) { var theme = snapshot.data; - TextStyle themedTextStyle = TextStyle( - color: themeValueParserService.parseColor(theme.primaryTextColor), - fontFamilyFallback: ['NunitoSans'], - fontSize: (style != null && style.fontSize != null) - ? style.fontSize - : fontSize); + TextStyle themedTextStyle = themeService + .getThemedTextStyle(theme) + .merge(TextStyle( + fontSize: (style != null && style.fontSize != null) + ? style.fontSize + : fontSize)); if (style != null) { themedTextStyle = themedTextStyle.merge(style); diff --git a/pubspec.yaml b/pubspec.yaml index 1200d93e7..2dc675e75 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -160,6 +160,17 @@ flutter: style: normal - asset: assets/fonts/NunitoSans-Bold.ttf style: italic + - family: DejaVuSans + fonts: + - asset: assets/fonts/DejaVuSans.ttf + style: normal + weight: 400 + - asset: assets/fonts/DejaVuSans-Bold.ttf + style: normal + weight: 700 + - asset: assets/fonts/DejaVuSans-ExtraLight.ttf + style: normal + weight: 200 - family: VisbyRoundCF fonts: - asset: assets/fonts/VisbyRoundCF-Regular.otf