setTheme method
Set the current theme by ID.
This will automatically disable followSystemTheme. To change theme while keeping system following enabled, use setFollowSystemTheme.
themeId - The ID of the theme to set.
remember - If true, sets this theme as the preferred theme for its type
(light or dark). This is used when following system theme to
remember which theme variant the user prefers.
Implementation
Future<void> setTheme(String themeId, {bool remember = false}) async {
final theme = getThemeById(themeId);
if (theme == null) {
throw ArgumentError('Theme with id "$themeId" not found.');
}
// Disable follow system theme on manual set
if (_followSystemTheme) {
_followSystemTheme = false;
await _storage.saveFollowSystem(false);
}
// Optionally remember this theme as preferred for its type
if (remember) {
if (theme.type == NyThemeType.dark) {
_preferredDarkThemeId = themeId;
await _storage.savePreferredDarkThemeId(themeId);
} else {
_preferredLightThemeId = themeId;
await _storage.savePreferredLightThemeId(themeId);
}
}
_setThemeInternal(themeId, notify: true, persist: true);
}