Jisho-Study-Tool/lib/bloc/theme/theme_bloc.dart

32 lines
829 B
Dart
Raw Permalink Normal View History

2021-12-01 23:09:53 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
2021-12-06 20:26:52 +01:00
import 'package:get_it/get_it.dart';
2021-08-08 23:16:54 +02:00
import 'package:shared_preferences/shared_preferences.dart';
2021-12-01 23:09:53 +01:00
import '../../models/themes/theme.dart';
2021-08-08 23:16:54 +02:00
export 'package:flutter_bloc/flutter_bloc.dart';
export 'package:jisho_study_tool/models/themes/theme.dart';
part 'theme_event.dart';
part 'theme_state.dart';
class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {
2021-12-01 23:09:53 +01:00
ThemeBloc() : super(const LightThemeState()) {
2021-12-06 20:26:52 +01:00
on<SetTheme>(
(event, emit) => emit(
event.themeIsDark ? const DarkThemeState() : const LightThemeState(),
),
);
2021-08-08 23:16:54 +02:00
2021-12-06 20:26:52 +01:00
add(
SetTheme(
themeIsDark: GetIt.instance
.get<SharedPreferences>()
.getBool('darkThemeEnabled') ??
false,
),
);
2021-08-08 23:16:54 +02:00
}
}