2021-12-01 23:09:53 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2022-01-19 16:06:03 +01:00
|
|
|
import 'package:flutter/scheduler.dart';
|
2021-12-01 23:09:53 +01:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2021-08-08 23:16:54 +02:00
|
|
|
|
2021-12-01 23:09:53 +01:00
|
|
|
import '../../models/themes/theme.dart';
|
2022-01-19 16:06:03 +01:00
|
|
|
import '../../settings.dart';
|
2021-12-01 23:09:53 +01:00
|
|
|
|
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
|
|
|
|
2022-01-19 16:06:03 +01:00
|
|
|
final bool autoThemeIsDark =
|
|
|
|
SchedulerBinding.instance!.window.platformBrightness == Brightness.dark;
|
|
|
|
|
2021-12-06 20:26:52 +01:00
|
|
|
add(
|
|
|
|
SetTheme(
|
2022-01-19 16:06:03 +01:00
|
|
|
themeIsDark: autoThemeEnabled ? autoThemeIsDark : darkThemeEnabled,
|
2021-12-06 20:26:52 +01:00
|
|
|
),
|
|
|
|
);
|
2021-08-08 23:16:54 +02:00
|
|
|
}
|
|
|
|
}
|