This commit is contained in:
2026-04-07 11:30:22 +02:00
parent 4bbd1edf48
commit 130780cbb8
20 changed files with 426 additions and 131 deletions

View File

@@ -0,0 +1,27 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flux/data/enums.dart';
import 'package:get_it/get_it.dart';
import 'package:shared_preferences/shared_preferences.dart';
part 'theme_events.dart';
part 'theme_state.dart';
class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {
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(PrefKeys.theme.value),
),
),
);
});
on<ChangeThemeEvent>((event, emit) async {
await _prefs.setString(PrefKeys.theme.value, event.appThemeMode.value);
emit(state.copyWith(currentTheme: event.appThemeMode));
});
}
}