This commit is contained in:
2026-04-06 10:55:56 +02:00
parent c6c61f1a31
commit 4930d25e58
15 changed files with 658 additions and 11 deletions

View File

@@ -8,20 +8,19 @@ part 'theme_events.dart';
part 'theme_state.dart';
class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {
static const String _savedThemeKey = "themeModeSetting";
final SharedPreferences _prefs = GetIt.I.get<SharedPreferences>();
ThemeBloc() : super(ThemeState(currentTheme: AppThemeMode.system)) {
on<LoadThemeEvent>((event, emit) {
emit(
state.copyWith(
currentTheme: AppThemeMode.fromValue(
_prefs.getString(_savedThemeKey),
_prefs.getString(PrefKeys.theme.value),
),
),
);
});
on<ChangeThemeEvent>((event, emit) async {
await _prefs.setString(_savedThemeKey, event.appThemeMode.value);
await _prefs.setString(PrefKeys.theme.value, event.appThemeMode.value);
emit(state.copyWith(currentTheme: event.appThemeMode));
});
}