AppTheme API
The AppTheme API provides access to your generated theme tokens in Flutter widgets.
AppThemeProvider
Section titled “AppThemeProvider”A widget that provides theme access to the widget tree.
Constructor
Section titled “Constructor”AppThemeProvider({ required AppThemeNotifier notifier, required Widget child,})Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
notifier | AppThemeNotifier | Manages theme mode state |
child | Widget | Child widget to render |
void main() { runApp( AppThemeProvider( notifier: AppThemeNotifier(initialMode: AppThemeMode.light), child: MyApp(), ), );}AppThemeNotifier
Section titled “AppThemeNotifier”Manages the current theme mode and notifies listeners of changes.
Constructor
Section titled “Constructor”AppThemeNotifier({ required AppThemeMode initialMode,})Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
setMode(AppThemeMode mode) | void | Switches to the specified theme mode |
toggleMode() | void | Toggles between light and dark modes |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
currentMode | AppThemeMode | The currently active theme mode |
currentTheme | AppTheme | The theme data for the current mode |
AppThemeMode
Section titled “AppThemeMode”Enumeration of available theme modes.
enum AppThemeMode { light, dark,}AppTheme
Section titled “AppTheme”The main generated theme class containing all your tokens.
Accessing Theme Data
Section titled “Accessing Theme Data”Use the extension method on BuildContext:
final theme = context.theme;Properties
Section titled “Properties”The available properties depend on your token structure. Common categories include:
| Property | Type | Description |
|---|---|---|
colors | AppThemeColors | Color tokens |
typography | AppThemeTypography | Text style tokens |
dimensions | AppThemeDimensions | Spacing and sizing tokens |
Example
Section titled “Example”class MyWidget extends StatelessWidget { @override Widget build(BuildContext context) { final theme = context.theme;
return Container( color: theme.colors.brand.primary, padding: EdgeInsets.all(theme.dimensions.spacing.md), child: Text( 'Hello World', style: theme.typography.heading.large, ), ); }}Runtime Overrides
Section titled “Runtime Overrides”Apply server-side token overrides dynamically.
Methods
Section titled “Methods”| Method | Description |
|---|---|
applyOverrides(Map<String, dynamic> overrides) | Apply token overrides at runtime |
clearOverrides() | Remove all applied overrides |
Example
Section titled “Example”// Apply overrides from server responsecontext.theme.applyOverrides({ 'colors.brand.primary': '#FF0000',});