setThemeMode method

Future<void> setThemeMode(
  1. AppThemeMode mode
)

Changes the theme mode

Implementation

Future<void> setThemeMode(AppThemeMode mode) async {
  final old = state.themeMode;
  emit(state.copyWith(themeMode: mode));

  // Update ThemeCubit immediately
  _themeCubit?.setTheme(mode);

  final result = await _repository.setThemeMode(mode);
  result.fold(
    (failure) {
      emit(state.copyWith(themeMode: old));
      _themeCubit?.setTheme(old);
    },
    (_) async {
      // Also save to full preferences
      await _repository.saveAppPreferences(state.toAppPreferences());
    },
  );
}