Skip to content
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
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();
await FlutterSkin.init(
apiKey:
"fsk_dc0054468a27dde1671142669f2065f93870975bbb773f1af0ab5898797956db",
"fsk_b0ce429cfbded17bbca66eef6e68bd1f0b7fbf9d74be0c3a0ac8b2e0554b7919",
);
runApp(const MyApp());
}
Expand Down
21 changes: 18 additions & 3 deletions lib/flutter_skin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_skin/models/project_config.dart';
import 'package:flutter_skin/remote/fskin_remote_config.dart';
import 'package:flutter_skin/services/fskin_logger.dart';
import 'package:flutter_skin/services/fskin_subscriber.dart';
import 'package:google_fonts/google_fonts.dart';

class FlutterSkin with WidgetsBindingObserver {
static FlutterSkin? _instance;
Expand Down Expand Up @@ -88,13 +89,27 @@ class FlutterSkin with WidgetsBindingObserver {

/// Query current active theme from remote config and return as ThemeData.
/// When there's no active theme, the result is null or fallbackTheme if provided.
static ThemeData? toThemeData({ThemeData? fallbackTheme}) {
static ThemeData? toThemeData({
ThemeData? fallbackTheme,
String? fallbackFont,
}) {
ProjectConfig? config = remoteConfig.projectConfig;
ColorScheme? colors = config?.skin?.colors;
String? fontFamily = config?.skin?.fontFamily;

String? fontFamily = (config?.skin?.fontFamily?.isEmpty == true)
? null
: config?.skin?.fontFamily;
String? googleFont = config?.skin?.googleFont?.isEmpty == true
? null
: config?.skin?.googleFont;

ThemeData remoteTheme = ThemeData(
colorScheme: colors,
fontFamily: fontFamily,
fontFamily:
fontFamily ??
(googleFont != null
? GoogleFonts.getFont(googleFont).fontFamily
: fallbackFont ?? 'Roboto'),
);
if (colors == null) {
if (fallbackTheme != null) {
Expand Down
3 changes: 3 additions & 0 deletions lib/models/skin_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SkinModel {
final DateTime? deletedAt;
final ColorScheme? colors;
final String? fontFamily;
final String? googleFont;

SkinModel({
required this.id,
Expand All @@ -20,6 +21,7 @@ class SkinModel {
required this.createdAt,
required this.colors,
this.fontFamily,
this.googleFont,
this.publishedAt,
this.deletedAt,
});
Expand All @@ -45,6 +47,7 @@ class SkinModel {
? fromSchemaString(tokens)?.colors
: null,
fontFamily: map['font'] as String?,
googleFont: map['googleFont'] as String?,
);
}

Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies:
flutter:
sdk: flutter
http: ^1.6.0
google_fonts: ^8.2.1
Comment thread
koukibadr marked this conversation as resolved.

dev_dependencies:
flutter_test:
Expand Down
Loading