NyThemeManager class

Singleton class to manage app themes.

Features:

Example:

// Register themes
NyThemeManager.instance.registerThemes(appThemes, initialThemeId: 'light_theme');

// Change theme (auto-disables followSystemTheme)
NyThemeManager.instance.setTheme('dark_theme');

// Change theme and remember as preferred for its type
NyThemeManager.instance.setTheme('dark_amoled', remember: true);

// Listen to theme changes
NyThemeManager.instance.onThemeChanged.listen((themeId) {
  print('Theme changed to: $themeId');
});

// Get all dark themes
final darkThemes = NyThemeManager.instance.darkThemes;

// Get color styles
final colors = NyThemeManager.instance.colorStyles<MyColorStyles>();
Mixed-in types

Properties

currentTheme BaseThemeConfig?
Get the current BaseThemeConfig.
no setter
currentThemeId String
Get the current theme ID.
no setter
darkTheme BaseThemeConfig?
Get the first dark theme from registered themes.
no setter
darkThemes List<BaseThemeConfig>
Get all dark themes.
no setter
effectiveDarkTheme BaseThemeConfig?
Get the effective dark theme (preferred or first dark theme).
no setter
effectiveLightTheme BaseThemeConfig?
Get the effective light theme (preferred or first light theme).
no setter
followSystemTheme bool
Get whether the app is following system theme.
no setter
hashCode int
The hash code for this object.
no setterinherited
isDark bool
Check if the current theme is dark.
no setter
isInitialized bool
Get whether the manager has been initialized.
no setter
lightTheme BaseThemeConfig?
Get the first light theme from registered themes.
no setter
lightThemes List<BaseThemeConfig>
Get all light themes.
no setter
onThemeChanged Stream<String>
Stream of theme change events.
no setter
preferredDarkThemeId String?
Get the preferred dark theme ID.
no setter
preferredLightThemeId String?
Get the preferred light theme ID.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
themeData ThemeData?
Get the current ThemeData.
no setter
themeNotifier ValueNotifier<String>
Get the theme notifier for reactive updates.
no setter
themes List<BaseThemeConfig>
Get all registered themes.
no setter

Methods

clearSavedTheme() Future<void>
Clear all saved theme data.
colorStyles<T>() → T
Get typed color styles from the current theme.
colorStylesFromTheme<T>(String themeId) → T
Get color styles from a specific theme by ID.
didChangeAccessibilityFeatures() → void
Called when the system changes the set of currently active accessibility features.
inherited
didChangeAppLifecycleState(AppLifecycleState state) → void
Called when the system puts the app in the background or returns the app to the foreground.
inherited
didChangeLocales(List<Locale>? locales) → void
Called when the system tells the app that the user's locale has changed. For example, if the user changes the system language settings.
inherited
didChangeMetrics() → void
Called when the application's dimensions change. For example, when a phone is rotated.
inherited
didChangePlatformBrightness() → void
Called when the platform brightness changes.
override
didChangeTextScaleFactor() → void
Called when the platform's text scale factor changes.
inherited
didChangeViewFocus(ViewFocusEvent event) → void
Called whenever the PlatformDispatcher receives a notification that the focus state on a view has changed.
inherited
didHaveMemoryPressure() → void
Called when the system is running low on memory.
inherited
didPopRoute() Future<bool>
Called when the system tells the app to pop the current route, such as after a system back button press or back gesture.
inherited
didPushRoute(String route) Future<bool>
Called when the host tells the application to push a new route onto the navigator.
inherited
didPushRouteInformation(RouteInformation routeInformation) Future<bool>
Called when the host tells the application to push a new RouteInformation and a restoration state onto the router.
inherited
didRequestAppExit() Future<AppExitResponse>
Called when a request is received from the system to exit the application.
inherited
dispose() → void
Dispose of resources.
getThemeById(String id) BaseThemeConfig?
Get a theme by ID.
getThemesByType(NyThemeType type) List<BaseThemeConfig>
Get themes by type.
handleCancelBackGesture() → void
Called when a predictive back gesture is canceled, indicating that no navigation should occur.
inherited
handleCommitBackGesture() → void
Called when a predictive back gesture is finished successfully, indicating that the current route should be popped.
inherited
handleStartBackGesture(PredictiveBackEvent backEvent) bool
Called at the start of a predictive back gesture.
inherited
handleUpdateBackGestureProgress(PredictiveBackEvent backEvent) → void
Called when a predictive back gesture moves.
inherited
init() Future<void>
Initialize the theme manager.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerThemes<T>(List<BaseThemeConfig<T>> themes, {String? initialThemeId}) → void
Register themes with the manager.
setFollowSystemTheme(bool follow) Future<void>
Set whether to follow system theme changes.
setPreferredDarkTheme(String themeId) Future<void>
Set the preferred dark theme for system theme following.
setPreferredLightTheme(String themeId) Future<void>
Set the preferred light theme for system theme following.
setTheme(String themeId, {bool remember = false}) Future<void>
Set the current theme by ID.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance NyThemeManager
Get the singleton instance of NyThemeManager.
no setter