mirror of
https://github.com/madari-media/madari-oss.git
synced 2026-04-21 15:11:57 +00:00
fix: theming preference
This commit is contained in:
parent
2fab0e7745
commit
2a55da488c
2 changed files with 30 additions and 5 deletions
|
|
@ -8,6 +8,7 @@ import 'package:universal_platform/universal_platform.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
import '../../pocketbase/service/pocketbase.service.dart';
|
import '../../pocketbase/service/pocketbase.service.dart';
|
||||||
|
import '../../theme/theme/app_theme.dart';
|
||||||
import '../../widgetter/plugin_base.dart';
|
import '../../widgetter/plugin_base.dart';
|
||||||
import '../../widgetter/plugins/stremio/stremio_plugin.dart';
|
import '../../widgetter/plugins/stremio/stremio_plugin.dart';
|
||||||
|
|
||||||
|
|
@ -17,7 +18,7 @@ Future startupApp() async {
|
||||||
MediaKit.ensureInitialized();
|
MediaKit.ensureInitialized();
|
||||||
|
|
||||||
await AppPocketBaseService.ensureInitialized();
|
await AppPocketBaseService.ensureInitialized();
|
||||||
|
await AppTheme().ensureInitialized();
|
||||||
await SelectedProfileService.instance.initialize();
|
await SelectedProfileService.instance.initialize();
|
||||||
|
|
||||||
if (UniversalPlatform.isDesktop) {
|
if (UniversalPlatform.isDesktop) {
|
||||||
|
|
@ -27,6 +28,7 @@ Future startupApp() async {
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
PluginRegistry.instance.reset();
|
PluginRegistry.instance.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginRegistry.instance.registerPlugin(
|
PluginRegistry.instance.registerPlugin(
|
||||||
StremioCatalogPlugin(),
|
StremioCatalogPlugin(),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import '../provider/theme_provider.dart';
|
import '../provider/theme_provider.dart';
|
||||||
import '../utils/color_utils.dart';
|
import '../utils/color_utils.dart';
|
||||||
|
|
||||||
class AppTheme {
|
class AppTheme {
|
||||||
static final AppTheme _instance = AppTheme._internal();
|
static final AppTheme _instance = AppTheme._internal();
|
||||||
|
static const String _primaryColorKey = 'primary_color';
|
||||||
|
static const String _isDarkModeKey = 'is_dark_mode';
|
||||||
|
|
||||||
factory AppTheme() {
|
factory AppTheme() {
|
||||||
return _instance;
|
return _instance;
|
||||||
|
|
@ -18,13 +21,33 @@ class AppTheme {
|
||||||
ThemeProvider get themeProvider => _themeProvider;
|
ThemeProvider get themeProvider => _themeProvider;
|
||||||
ColorUtils get colorUtils => _colorUtils;
|
ColorUtils get colorUtils => _colorUtils;
|
||||||
|
|
||||||
void toggleTheme() => _themeProvider.toggleTheme();
|
Future<void> ensureInitialized() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
void setPrimaryColor(Color color) => _themeProvider.setPrimaryColor(color);
|
final isDarkMode = prefs.getBool(_isDarkModeKey) ?? false;
|
||||||
|
if (isDarkMode) _themeProvider.toggleTheme();
|
||||||
|
|
||||||
void setPrimaryColorFromRGB(int r, int g, int b) {
|
final primaryColorValue = prefs.getInt(_primaryColorKey);
|
||||||
Color color = _colorUtils.colorFromRGB(r, g, b);
|
if (primaryColorValue != null) {
|
||||||
|
_themeProvider.setPrimaryColor(Color(primaryColorValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> toggleTheme() async {
|
||||||
|
_themeProvider.toggleTheme();
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setBool(_isDarkModeKey, _themeProvider.isDarkMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setPrimaryColor(Color color) async {
|
||||||
_themeProvider.setPrimaryColor(color);
|
_themeProvider.setPrimaryColor(color);
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setInt(_primaryColorKey, color.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setPrimaryColorFromRGB(int r, int g, int b) async {
|
||||||
|
Color color = _colorUtils.colorFromRGB(r, g, b);
|
||||||
|
await setPrimaryColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
ThemeData getCurrentTheme() => _themeProvider.getTheme();
|
ThemeData getCurrentTheme() => _themeProvider.getTheme();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue