diff --git a/example/assets/fonts/opensans.ttf b/example/assets/fonts/opensans.ttf new file mode 100644 index 0000000..67a73b8 Binary files /dev/null and b/example/assets/fonts/opensans.ttf differ diff --git a/example/assets/fonts/robotomono.ttf b/example/assets/fonts/robotomono.ttf new file mode 100644 index 0000000..3806bfb Binary files /dev/null and b/example/assets/fonts/robotomono.ttf differ diff --git a/example/lib/main.dart b/example/lib/main.dart index c5e1ef2..b8d124c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -6,7 +6,7 @@ void main() async { WidgetsFlutterBinding.ensureInitialized(); await FlutterSkin.init( apiKey: - "fsk_b0ce429cfbded17bbca66eef6e68bd1f0b7fbf9d74be0c3a0ac8b2e0554b7919", + "fsk_dc0054468a27dde1671142669f2065f93870975bbb773f1af0ab5898797956db", ); runApp(const MyApp()); } diff --git a/example/lib/pages/home_page.dart b/example/lib/pages/home_page.dart index ba51e91..b3f3e18 100644 --- a/example/lib/pages/home_page.dart +++ b/example/lib/pages/home_page.dart @@ -183,7 +183,10 @@ class _MyHomePageState extends State { ], ), ), - child: Text(movie.title, style: TextStyle(color: Theme.of(context).colorScheme.onTertiary)), + child: Text( + movie.title, + style: TextStyle(color: Theme.of(context).colorScheme.onTertiary), + ), ), content: SingleChildScrollView( child: Column( @@ -202,12 +205,22 @@ class _MyHomePageState extends State { ), actions: [ TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(Theme.of(context).colorScheme.secondaryContainer), - foregroundColor: MaterialStateProperty.all(Theme.of(context).colorScheme.onSecondaryContainer), + onPressed: () { + Navigator.pop(context); + }, + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.tertiaryContainer, + borderRadius: BorderRadius.circular(4), + ), + child: Text( + 'Close', + style: TextStyle( + color: Theme.of(context).colorScheme.onTertiaryContainer, + ), + ), ), - onPressed: () => Navigator.pop(context), - child: const Text('Close'), ), ], ), diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 9635410..160a971 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -74,17 +74,13 @@ flutter: # "family" key with the font family name, and a "fonts" key with a # list giving the asset and other descriptors for the font. For # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 + fonts: + - family: OpenSans + fonts: + - asset: assets/fonts/opensans.ttf + - family: Roboto + fonts: + - asset: assets/fonts/robotomono.ttf # # For details regarding fonts from package dependencies, # see https://flutter.dev/to/font-from-package diff --git a/lib/flutter_skin.dart b/lib/flutter_skin.dart index 23845c7..bb988c4 100644 --- a/lib/flutter_skin.dart +++ b/lib/flutter_skin.dart @@ -15,6 +15,9 @@ class FlutterSkin with WidgetsBindingObserver { static Stream get onSkinChanged => remoteConfig.onSkinChanged; static final FskinLogger _logger = FskinLogger(); + /// Returns the font family of the current active theme from the remote configuration. + static String? get themeFont => remoteConfig.projectConfig?.skin?.fontFamily; + // Private constructor FlutterSkin._(); @@ -88,7 +91,11 @@ class FlutterSkin with WidgetsBindingObserver { static ThemeData? toThemeData({ThemeData? fallbackTheme}) { ProjectConfig? config = remoteConfig.projectConfig; ColorScheme? colors = config?.skin?.colors; - ThemeData remoteTheme = ThemeData(colorScheme: colors); + String? fontFamily = config?.skin?.fontFamily; + ThemeData remoteTheme = ThemeData( + colorScheme: colors, + fontFamily: fontFamily, + ); if (colors == null) { if (fallbackTheme != null) { _logger.logWarning('No active theme found. Returning fallback theme.'); diff --git a/lib/models/skin_model.dart b/lib/models/skin_model.dart index fb6ea35..6dae097 100644 --- a/lib/models/skin_model.dart +++ b/lib/models/skin_model.dart @@ -10,6 +10,7 @@ class SkinModel { final DateTime? publishedAt; final DateTime? deletedAt; final ColorScheme? colors; + final String? fontFamily; SkinModel({ required this.id, @@ -18,6 +19,7 @@ class SkinModel { required this.version, required this.createdAt, required this.colors, + this.fontFamily, this.publishedAt, this.deletedAt, }); @@ -42,6 +44,7 @@ class SkinModel { colors: tokens is Map ? fromSchemaString(tokens)?.colors : null, + fontFamily: map['font'] as String?, ); }