saveAppPreferences method

  1. @override
Future<Either<Failure, void>> saveAppPreferences(
  1. AppPreferences prefs
)
override

Saves all app preferences

Implementation

@override
Future<Either<Failure, void>> saveAppPreferences(AppPreferences prefs) async {
  try {
    await _isar.writeTxn(() async {
      final existing = await _isar.appPreferencesDtos.get(_prefsId);
      // We re-use logic from "fromOnboardingPreferences" but adapting for update
      // Since we don't have a direct "fromAppPreferences", we map manually or use a helper
      // But AppPreferencesDto is derived from OnboardingPreferences in prompt.
      // Let's manually map here to be safe and thorough.

      final dto = existing ?? AppPreferencesDto()
        ..id = _prefsId;

      dto.locale = prefs.locale;
      dto.themeMode = prefs.themeMode.name;
      dto.textSize = prefs.textSize.name;
      dto.notificationsEnabled = prefs.notificationsEnabled;
      dto.highContrastEnabled = prefs.highContrastEnabled;

      await _isar.appPreferencesDtos.put(dto);
    });
    return const Right(null);
  } catch (e) {
    return Left(CacheFailure("Failed to save app preferences: $e"));
  }
}