ThemeService class final

Service for managing application themes and theme switching.

Holds two layers:

  • mode — the user's stated intent. Can be ThemeMode.light, ThemeMode.dark, or ThemeMode.system. Updated through changeTheme / toggleTheme.
  • currentMode — the actively-resolved mode. Always either ThemeMode.light or ThemeMode.dark (never system). Reactively tracks both mode AND the OS-level platform brightness, so an OS dark-mode toggle flips this when the intent is system.

Use currentMode to look up ThemeData and pass to MaterialApp. Use mode when you need the user intent (e.g. to highlight which of light / dark / system is currently selected in a UI control).

Built on MobX, so reads inside Observer / autorun / reaction automatically rebuild on changes.

Constructors

ThemeService()

Properties

currentMode → Computed<ThemeMode>
The actively-resolved theme mode. Always either ThemeMode.light or ThemeMode.dark — never ThemeMode.system. Reactive to changes in both mode and the OS platform brightness.
latefinal
hashCode int
The hash code for this object.
no setterinherited
mode → Observable<ThemeMode>
The user's stated theme intent. Update through changeTheme / toggleTheme. Defaults to ThemeMode.system.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

changeTheme(ThemeMode requestedMode) → void
Updates the user's intent. Pass ThemeMode.system to follow the OS theme — currentMode then resolves to light / dark based on the platform brightness and re-resolves automatically when the OS theme is toggled.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setThemes(Map<ThemeMode, ThemeData> themes) → void
Configures theme data for different theme modes.
theme(ThemeMode mode) ThemeData?
Gets the theme data for the specified theme mode. Returns null if no theme data is configured for the specified mode.
toggleTheme() → void
Flips between light and dark, taking the resolved currentMode as the starting point. Always sets mode to a concrete ThemeMode.light or ThemeMode.dark — toggling out of ThemeMode.system.
toString() String
A string representation of this object.
inherited

Operators

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