ThemeTokens class final
A project's theme as published: what the runtime draws itself (dialogs,
toasts, the loading and error screens), what layouts read at run time
(${theme.primary}, ${theme.colors.brand}, ${theme.text.title.fontSize},
${theme.isDark}) and what an app can read to match its own widgets to a
layout. Every token is optional.
dark holds the colors to use in dark mode where they differ: the
runtime reads forBrightness (dark: true), so a binding to
${theme.surface} shows the dark surface on a device in dark mode.
mode is the site's light or dark choice (Flutter's MaterialApp.themeMode):
system follows the device; a setThemeMode action changes it at run
time. Older runtimes ignore colors, textStyles, dark and mode.
- Annotations
-
- @immutable
Constructors
-
ThemeTokens({Color? primary, Color? onPrimary, Color? surface, Color? onSurface, Color? error, Color? success, Color? warning, String? fontFamily, String? titleFontFamily, double? radius, double? buttonRadius, Map<
String, Color> colors = const {}, Map<String, TextStyle> textStyles = const {}, ThemeTokens? dark, List<MediaRule> media = const [], ThemeMode mode = ThemeMode.system, Map<String, double> spacing = const {}, Map<String, double> radii = const {}, Map<String, double> sizes = const {}, Map<String, List< shadows = const {}, Map<Effect> >String, int> durations = const {}, Map<String, String> curves = const {}}) -
const
Properties
-
Corner radius of buttons.
final
-
colorNames
→ Iterable<
String> -
Every name color reads.
no setter
-
colors
→ Map<
String, Color> -
Every named color of the project by key (themeKey of its name:
"Brand Blue" is
brandBlue), read as${theme.colors.brandBlue}.final -
curves
→ Map<
String, String> -
Easing curves by name (Flutter's
Curves:easeOut,easeInOut...), read as${theme.curves.standard}.final - dark → ThemeTokens?
-
The colors for dark mode: the tokens and colors that differ from the
light ones (its other fields are not used).
final
-
durations
→ Map<
String, int> -
Durations in milliseconds by name (Flutter's
Durations:short2,medium1...; a design system's own names), read as${theme.durations.medium}.final - error → Color?
-
Destructive buttons and error toasts.
final
- fontFamily → String?
-
Font family of body text and buttons.
final
- hasDark → bool
-
Whether dark gives any color.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- isEmpty → bool
-
Whether no token is set.
no setter
-
media
→ List<
MediaRule> -
The theme by screen size, as CSS media queries over custom properties:
each rule's
patchis a theme's JSON ({"textStyles": {"display": {"fontSize": 40}}, "colors": {...}}) merged over this one while the screen meets its conditions (atScreen). A type scale that changes at a breakpoint is written once here, not on every text.final - mode → ThemeMode
-
Which of the light and dark colors a site starts in (Flutter's
ThemeMode):systemfollows the device,lightanddarkare fixed. AsetThemeModeaction changes it while the site runs;${theme.mode}reads it and${theme.isDark}whether the screen is dark.final - onPrimary → Color?
-
Text on primary.
final
- onSurface → Color?
-
Text on surface.
final
- primary → Color?
-
Primary buttons and info toasts.
final
-
radii
→ Map<
String, double> -
Corner radii by name (
{"control": 7, "panel": 8, "dialog": 12}; Flutter'sRadius.circular), read as${theme.radii.panel}.final - radius → double?
-
Corner radius of dialogs.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
scaleNames
→ Map<
String, Iterable< String> > -
The keys of the named scales (spacing, radii, sizes, shadows,
durations, curves) with their names: what
${theme.<scale>.<name>}may read.no setter -
shadows
→ Map<
String, List< Effect> > -
Shadows by name (Flutter's
BoxShadowlists, askElevationToShadowgives one per elevation): each a list of drop shadows asdecoration.effectstakes them, read as${theme.shadows.level3}. dark may give other shadows for dark mode.final -
sizes
→ Map<
String, double> -
Other lengths by name: a control scale's heights (
{"compact": 28, "large": 44}), icon sizes, a panel's width; read as${theme.sizes.compact}.final -
spacing
→ Map<
String, double> -
The spacing scale: gaps and paddings by name (
{"1": 4, "2": 8, "3": 12}or{"sm": 8, "md": 16}), read as${theme.spacing.md}. Flutter has no spacing token; a design system names its steps here.final - success → Color?
-
Success toasts.
final
- surface → Color?
-
Dialog backgrounds.
final
-
textStyles
→ Map<
String, TextStyle> -
Every named text style by key, read as
${theme.text.title.fontSize}and named by a text's style ("style": "title", or{"from": "title", ...}to change some of its fields). A style may itself startfromanother and name colors; textStyle gives it resolved.final - titleFontFamily → String?
-
Font family of titles.
final
- warning → Color?
-
Warning toasts.
final
Methods
-
atScreen(
double width, double? height, Breakpoints breakpoints) → ThemeTokens -
These tokens on a screen
width×height: media rules that hold merged over them in order (a JSON merge patch of the theme). Itself when none holds. -
color(
String name) → Color? -
The color named
name: a key of colors, else a role (primary,onSurface...). A color may name another ("accent": "ember"). -
forBrightness(
{required bool dark}) → ThemeTokens -
These tokens for a light or
darkscreen: in dark mode each colordarkgives over the light one. -
mergedWith(
ThemeTokens over) → ThemeTokens -
These tokens with
over's over them, field by field (a JSON merge patch of the theme): a site's theme over its design system's tokens. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resolvedRoles(
) → ThemeTokens -
The roles (Flutter's
ColorSchemenames: primary, onPrimary, surface, onSurface, error, and success, warning) as colors: a role that names a theme color ("primary": "forest") is that color, through any chain of names, as any color naming another is. A role whose name the theme does not have is null. Controls and the runtime read the roles through this. A role written inside colors ("colors": {"primary": ...}) is not a role: validation reports it (theme_role_in_colors). -
textStyle(
String name) → TextStyle? -
The text style named
name, resolved: the styles it startsfrommerged in order (TextStyle.merge), its color names read from colors. Null when there is no such style (or it starts from itself). -
toJson(
) → Json -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
fromJson(
Object? json) → ThemeTokens -
themeKey(
String name) → String -
The key a style named
namehas in colors and textStyles: its words in camel case ("On Primary" isonPrimary, "Title / Large" istitleLarge).
Constants
- none → const ThemeTokens
-
roleNames
→ const List<
String> - The role names (resolvedRoles).