feat:theme changing done
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import 'package:food_delivery_client/food_delivery_client.dart';
|
||||
|
||||
part 'theme_event.dart';
|
||||
|
||||
part 'theme_state.dart';
|
||||
|
||||
part 'theme_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {
|
||||
final StorageService _storageService;
|
||||
|
||||
ThemeBloc(this._storageService) : super(const ThemeState()) {
|
||||
on<_Started>(_onStarted);
|
||||
on<_Changed>(_onChanged);
|
||||
}
|
||||
|
||||
void _onStarted(_Started event, Emitter<ThemeState> emit) {
|
||||
final isDark = _storageService.getBool(key: AppLocaleKeys.theme);
|
||||
|
||||
if (isDark) {
|
||||
emit(state.copyWith(themeMode: ThemeMode.dark));
|
||||
} else {
|
||||
emit(state.copyWith(themeMode: ThemeMode.light));
|
||||
}
|
||||
}
|
||||
|
||||
void _onChanged(_Changed event, Emitter<ThemeState> emit) {
|
||||
if (state.themeMode == ThemeMode.light) {
|
||||
_storageService.setBool(key: AppLocaleKeys.theme, value: true);
|
||||
emit(state.copyWith(themeMode: ThemeMode.dark));
|
||||
} else {
|
||||
_storageService.setBool(key: AppLocaleKeys.theme, value: false);
|
||||
emit(state.copyWith(themeMode: ThemeMode.light));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
part of 'theme_bloc.dart';
|
||||
|
||||
@freezed
|
||||
class ThemeEvent with _$ThemeEvent {
|
||||
const factory ThemeEvent.started() = _Started;
|
||||
const factory ThemeEvent.changed() = _Changed;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
part of 'theme_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class ThemeState with _$ThemeState {
|
||||
const factory ThemeState({@Default(ThemeMode.light) ThemeMode themeMode}) =
|
||||
_ThemeState;
|
||||
}
|
||||
Reference in New Issue
Block a user