setPreferredDarkTheme method

Future<void> setPreferredDarkTheme(
  1. String themeId
)

Set the preferred dark theme for system theme following.

This theme will be used when the system is in dark mode and followSystemTheme is enabled.

Useful when you have multiple dark themes (e.g., dark, dark_amoled, dark_blue) and want the user to choose which one to use for dark mode.

Implementation

Future<void> setPreferredDarkTheme(String themeId) async {
  final theme = getThemeById(themeId);
  if (theme == null || theme.type != NyThemeType.dark) {
    throw ArgumentError('Dark theme with id "$themeId" not found.');
  }

  _preferredDarkThemeId = themeId;
  await _storage.savePreferredDarkThemeId(themeId);

  // If currently following system and in dark mode, apply immediately
  if (_followSystemTheme && _isSystemDarkMode) {
    _setThemeInternal(themeId, notify: true, persist: true);
  }
}