selfprivacy.org.app/lib/logic/cubit/app_settings/app_settings_cubit.dart

42 lines
1.1 KiB
Dart
Raw Normal View History

2020-12-08 19:26:51 +00:00
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
2021-01-06 17:35:57 +00:00
import 'package:hive/hive.dart';
import 'package:selfprivacy/config/hive_config.dart';
2020-12-08 19:26:51 +00:00
export 'package:provider/provider.dart';
part 'app_settings_state.dart';
class AppSettingsCubit extends Cubit<AppSettingsState> {
AppSettingsCubit({
2021-03-15 15:39:44 +00:00
required bool isDarkModeOn,
required bool isOnbordingShowing,
2020-12-08 19:26:51 +00:00
}) : super(
2021-01-06 17:35:57 +00:00
AppSettingsState(
isDarkModeOn: isDarkModeOn,
isOnbordingShowing: isOnbordingShowing,
),
2020-12-08 19:26:51 +00:00
);
2021-01-06 17:35:57 +00:00
Box box = Hive.box(BNames.appSettings);
void load() {
2021-03-15 15:39:44 +00:00
bool? isDarkModeOn = box.get(BNames.isDarkModeOn);
bool? isOnbordingShowing = box.get(BNames.isOnbordingShowing);
2021-01-06 17:35:57 +00:00
emit(state.copyWith(
isDarkModeOn: isDarkModeOn,
isOnbordingShowing: isOnbordingShowing,
));
}
2021-03-15 15:39:44 +00:00
void updateDarkMode({required bool isDarkModeOn}) {
2021-01-06 17:35:57 +00:00
box.put(BNames.isDarkModeOn, isDarkModeOn);
emit(state.copyWith(isDarkModeOn: isDarkModeOn));
}
void turnOffOnboarding() {
box.put(BNames.isOnbordingShowing, false);
emit(state.copyWith(isOnbordingShowing: false));
2020-12-08 19:26:51 +00:00
}
}