NyTheme class
Class to help manage current theme in the app.
Example:
// Set theme by ID
NyTheme.set(context, id: 'dark_theme');
// Set theme and remember as preferred for its type
NyTheme.set(context, id: 'dark_amoled', remember: true);
// Get current theme
final theme = NyTheme.current();
// Check if dark mode
if (NyTheme.isDark()) {
// do something for dark mode
}
// Get all dark themes
final darkThemes = NyTheme.darkThemes();
// Set preferred dark theme for system theme following
NyTheme.setPreferredDark('dark_amoled');
Constructors
- NyTheme()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
all(
) → List< BaseThemeConfig> - Get all registered themes.
-
clearSavedTheme(
) → Future< void> - Clear all saved theme preferences.
-
colors<
T> () → T - Get typed color styles from the current theme.
-
current(
) → BaseThemeConfig? - Get the current BaseThemeConfig.
-
currentId(
) → String - Get the current theme ID.
-
darkThemes(
) → List< BaseThemeConfig> - Get all dark themes.
-
getById(
String id) → BaseThemeConfig? - Get a theme by its ID.
-
getByType(
NyThemeType type) → List< BaseThemeConfig> - Get themes by type.
-
isDark(
) → bool - Check if the current theme is dark.
-
isFollowingSystem(
) → bool - Check if the app is following system theme.
-
lightThemes(
) → List< BaseThemeConfig> - Get all light themes.
-
preferredDarkId(
) → String? - Get the preferred dark theme ID.
-
preferredLightId(
) → String? - Get the preferred light theme ID.
-
set(
BuildContext context, {required String id, bool remember = false}) → Future< void> - Changes the current theme.
-
setFollowSystem(
bool follow) → Future< void> - Enable or disable system theme following.
-
setPreferredDark(
String themeId) → Future< void> - Set the preferred dark theme for system theme following.
-
setPreferredLight(
String themeId) → Future< void> - Set the preferred light theme for system theme following.
-
themeData(
) → ThemeData? - Get the current ThemeData.