mirror of
https://github.com/h7x4/Jisho-Study-Tool.git
synced 2024-12-22 05:57:28 +01:00
32 lines
848 B
Dart
32 lines
848 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/scheduler.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import '../../models/themes/theme.dart';
|
|
import '../../settings.dart';
|
|
|
|
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> {
|
|
ThemeBloc() : super(const LightThemeState()) {
|
|
on<SetTheme>(
|
|
(event, emit) => emit(
|
|
event.themeIsDark ? const DarkThemeState() : const LightThemeState(),
|
|
),
|
|
);
|
|
|
|
final bool autoThemeIsDark =
|
|
SchedulerBinding.instance!.window.platformBrightness == Brightness.dark;
|
|
|
|
add(
|
|
SetTheme(
|
|
themeIsDark: autoThemeEnabled ? autoThemeIsDark : darkThemeEnabled,
|
|
),
|
|
);
|
|
}
|
|
}
|