Skip to content

AppTheme API

The AppTheme API provides access to your generated theme tokens in Flutter widgets.

A widget that provides theme access to the widget tree.

AppThemeProvider({
required AppThemeNotifier notifier,
required Widget child,
})
PropertyTypeDescription
notifierAppThemeNotifierManages theme mode state
childWidgetChild widget to render
void main() {
runApp(
AppThemeProvider(
notifier: AppThemeNotifier(initialMode: AppThemeMode.light),
child: MyApp(),
),
);
}

Manages the current theme mode and notifies listeners of changes.

AppThemeNotifier({
required AppThemeMode initialMode,
})
MethodReturnsDescription
setMode(AppThemeMode mode)voidSwitches to the specified theme mode
toggleMode()voidToggles between light and dark modes
PropertyTypeDescription
currentModeAppThemeModeThe currently active theme mode
currentThemeAppThemeThe theme data for the current mode

Enumeration of available theme modes.

enum AppThemeMode {
light,
dark,
}

The main generated theme class containing all your tokens.

Use the extension method on BuildContext:

final theme = context.theme;

The available properties depend on your token structure. Common categories include:

PropertyTypeDescription
colorsAppThemeColorsColor tokens
typographyAppThemeTypographyText style tokens
dimensionsAppThemeDimensionsSpacing and sizing tokens
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,
),
);
}
}

Apply server-side token overrides dynamically.

MethodDescription
applyOverrides(Map<String, dynamic> overrides)Apply token overrides at runtime
clearOverrides()Remove all applied overrides
// Apply overrides from server response
context.theme.applyOverrides({
'colors.brand.primary': '#FF0000',
});