toggleTheme static method
Toggles between the built-in light and dark themes.
If the current theme is light, switches to dark and vice versa.
Note: If a custom theme is currently active, instead of toggling, this method switches to the built-in theme that matches the custom theme's Brightness — Brightness.dark maps to 'dark' and Brightness.light maps to 'light'.
Example:
Themed.toggleTheme(); // light → dark
Themed.toggleTheme(); // dark → light
Themed.setTheme('ocean'); // ocean has Brightness.dark
Themed.toggleTheme(); // ocean → dark (built-in)
Implementation
static void toggleTheme() {
if (isCustomTheme) {
setTheme(
_instance.themeNotifier.value.brightness == Brightness.dark
? 'dark'
: 'light',
);
return;
}
setTheme(isLightMode ? 'dark' : 'light');
}