2022-12-18 16:02:18 +08:00
|
|
|
import 'package:flowy_infra/colorscheme/colorscheme.dart';
|
2023-07-03 04:07:11 -10:00
|
|
|
import 'package:flowy_infra/colorscheme/default_colorscheme.dart';
|
|
|
|
import 'plugins/service/plugin_service.dart';
|
2021-06-19 23:41:19 +08:00
|
|
|
|
2022-12-30 09:14:17 +05:30
|
|
|
class BuiltInTheme {
|
2023-04-03 23:51:26 -05:00
|
|
|
static const String defaultTheme = 'Default';
|
|
|
|
static const String dandelion = 'Dandelion';
|
|
|
|
static const String lavender = 'Lavender';
|
2022-12-30 09:14:17 +05:30
|
|
|
}
|
2021-12-24 20:20:48 +02:00
|
|
|
|
2021-06-19 23:41:19 +08:00
|
|
|
class AppTheme {
|
2022-12-18 16:02:18 +08:00
|
|
|
// metadata member
|
2023-07-03 04:07:11 -10:00
|
|
|
final bool builtIn;
|
2022-12-30 09:14:17 +05:30
|
|
|
final String themeName;
|
2022-12-18 16:02:18 +08:00
|
|
|
final FlowyColorScheme lightTheme;
|
|
|
|
final FlowyColorScheme darkTheme;
|
|
|
|
// static final Map<String, dynamic> _cachedJsonData = {};
|
|
|
|
|
|
|
|
const AppTheme({
|
2023-07-03 04:07:11 -10:00
|
|
|
required this.builtIn,
|
2022-12-30 09:14:17 +05:30
|
|
|
required this.themeName,
|
2022-12-18 16:02:18 +08:00
|
|
|
required this.lightTheme,
|
|
|
|
required this.darkTheme,
|
|
|
|
});
|
|
|
|
|
2023-07-03 04:07:11 -10:00
|
|
|
static const AppTheme fallback = AppTheme(
|
|
|
|
builtIn: true,
|
|
|
|
themeName: BuiltInTheme.defaultTheme,
|
|
|
|
lightTheme: DefaultColorScheme.light(),
|
|
|
|
darkTheme: DefaultColorScheme.dark(),
|
|
|
|
);
|
|
|
|
|
|
|
|
static Future<Iterable<AppTheme>> _plugins(FlowyPluginService service) async {
|
|
|
|
final plugins = await service.plugins;
|
|
|
|
return plugins.map((plugin) => plugin.theme).whereType<AppTheme>();
|
|
|
|
}
|
|
|
|
|
|
|
|
static Iterable<AppTheme> get builtins => themeMap.entries
|
|
|
|
.map(
|
|
|
|
(entry) => AppTheme(
|
|
|
|
builtIn: true,
|
|
|
|
themeName: entry.key,
|
|
|
|
lightTheme: entry.value[0],
|
|
|
|
darkTheme: entry.value[1],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
static Future<Iterable<AppTheme>> themes(FlowyPluginService service) async =>
|
|
|
|
[
|
|
|
|
...builtins,
|
|
|
|
...(await _plugins(service)),
|
|
|
|
];
|
|
|
|
|
|
|
|
static Future<AppTheme> fromName(
|
|
|
|
String themeName, {
|
|
|
|
FlowyPluginService? pluginService,
|
|
|
|
}) async {
|
|
|
|
pluginService ??= FlowyPluginService.instance;
|
|
|
|
for (final theme in await themes(pluginService)) {
|
|
|
|
if (theme.themeName == themeName) {
|
|
|
|
return theme;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw ArgumentError('The theme $themeName does not exist.');
|
2022-02-01 11:29:11 +08:00
|
|
|
}
|
|
|
|
}
|