/* SPDX-License-Identifier: GPL-3.0-or-later */ /* Copyright (C) 2024 Marco Groß */ import 'package:calorimeter/storage/storage.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class ThemeDataBloc extends Bloc { final FoodStorage storage; ThemeDataBloc(super.initialState, {required this.storage}) { on(switchTheme); } void switchTheme(ThemeToggleEvent event, Emitter emit) async { String newBrightness = 'light'; if (state.brightness == 'light') newBrightness = 'dark'; persistTheme(newBrightness); emit(ThemeState(brightness: newBrightness)); } void persistTheme(String brightness) async { storage.writeBrightness(brightness); } Future getPersistedTheme() async { return storage.readBrightness(); } } class ThemeToggleEvent { ThemeToggleEvent(); } class ThemeState { final String brightness; ThemeState({required this.brightness}); }