27 lines
652 B
Dart
27 lines
652 B
Dart
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter/services.dart';
|
|
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> {
|
|
final SharedPreferences prefs;
|
|
|
|
ThemeBloc({
|
|
required this.prefs,
|
|
required Brightness init,
|
|
}) : super(init) {
|
|
on<SetTheme>((event, emit) {
|
|
prefs.setBool('darkTheme', event.isDark);
|
|
emit(event.isDark ? Brightness.dark : Brightness.light);
|
|
});
|
|
}
|
|
}
|