toggleTheme method
- required bool isDark,
Toggles the theme between dark and light mode.
When isDark
is true, the theme is set to dark mode.
When isDark
is false, the theme is set to light mode.
Persists the chosen theme to SharedPreferences.
Emits a new ThemeState with the chosen isDark
and
ThemeMode.
Implementation
Future<void> toggleTheme({required final bool isDark}) async {
final newState = state.copyWith(
isDark: isDark,
themeMode: isDark ? ThemeMode.dark : ThemeMode.light,
);
await _persistTheme(newState);
emit(newState);
}