2022-02-04 04:22:35 +01:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2022-02-04 15:13:51 +01:00
|
|
|
import 'package:get_it/get_it.dart';
|
2022-02-04 04:22:35 +01:00
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
export 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
|
|
|
@immutable
|
|
|
|
class SetTheme {
|
|
|
|
final bool isDark;
|
|
|
|
const SetTheme(this.isDark);
|
|
|
|
}
|
|
|
|
|
|
|
|
class ThemeBloc extends Bloc<SetTheme, Brightness> {
|
|
|
|
ThemeBloc({
|
|
|
|
required Brightness init,
|
|
|
|
}) : super(init) {
|
|
|
|
on<SetTheme>((event, emit) {
|
2022-02-04 15:13:51 +01:00
|
|
|
GetIt.instance
|
|
|
|
.get<SharedPreferences>()
|
|
|
|
.setBool('darkTheme', event.isDark);
|
2022-02-04 04:22:35 +01:00
|
|
|
emit(event.isDark ? Brightness.dark : Brightness.light);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|