saveTheme method
- required ZetaThemeServiceData themeData,
override
Saves the provided theme data as the application's theme.
saveTheme
is a method used to save the current theme data.
Takes a ZetaThemeData
object that represents the theme to be saved.
Returns a Future
that completes when the theme data has been successfully saved.
Implementation
@override
Future<void> saveTheme({required ZetaThemeServiceData themeData}) async {
final preferences = await SharedPreferences.getInstance();
final List<Future<void>> futures = [];
if (themeData.fontFamily != null) {
futures.add(preferences.setString(_kFontFamily, themeData.fontFamily!));
}
if (themeData.themeMode != null) {
futures.add(preferences.setString(_kThemeMode, themeData.themeMode!.name));
}
if (themeData.contrast != null) {
futures.add(preferences.setString(_kContrast, themeData.contrast!.name));
}
if (themeData.themeId != null) {
futures.add(preferences.setString(_kThemeId, themeData.themeId!));
} else {
futures.add(preferences.remove(_kThemeId));
}
await Future.wait(futures);
}