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

Constructors

ThemeTokens({Color? primary, Color? onPrimary, Color? surface, Color? onSurface, Color? error, Color? success, Color? warning, String? fontFamily, String? titleFontFamily, double? radius, double? buttonRadius, String? iconStyle, 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<Effect>> shadows = const {}, Map<String, int> durations = const {}, Map<String, String> curves = const {}})
const

Properties

buttonRadius → double?
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
ground → Color?
The ground the theme draws on: its page, surface or primaryBackground, else its paper (background, bg, ground).
no setter
groundIsDark → bool
Whether ground is dark (its luminance under 0.35): the notation's roles take their dark values (notationRoles).
no setter
hasDark → bool
Whether dark gives any color.
no setter
hashCode → int
The hash code for this object.
no setteroverride
iconStyle → String?
The style a Material icon written by its bare name is drawn in by a UI written in the notation (outlined, rounded, sharp); null: filled, as written.
final
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 patch is 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): system follows the device, light and dark are fixed. A setThemeMode action 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's Radius.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 BoxShadow lists, as kElevationToShadow gives one per elevation): each a list of drop shadows as decoration.effects takes 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 start from another 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 dark screen: in dark mode each color dark gives 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
notationRole(String name) → Color?
The notation's role name (notationRoles) in this theme (already for its mode: forBrightness): its light value, or on a dark ground its value made from the theme's ink and ground. Null for another name.
resolvedRoles() → ThemeTokens
The roles (Flutter's ColorScheme names: 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: it is a color of that name.
textStyle(String name) → TextStyle?
The text style named name, resolved: the styles it starts from merged 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
withSiteTheme(ThemeTokens site) → ThemeTokens
These tokens (a design system's) with a site's theme over them (mergedWith), and what the design system makes from its accent made from the site's instead. A site that gives its own primary (or, where the design system's accent is its primary, its own colors.accent) and nothing else gets:

Operators

operator ==(Object other) → bool
The equality operator.
override

Static Methods

contrastOf(Color a, Color b) → double
The WCAG contrast ratio of two opaque colors (1 to 21).
fromJson(Object? json) → ThemeTokens
themeKey(String name) → String
The key a style named name has in colors and textStyles: its words in camel case ("On Primary" is onPrimary, "Title / Large" is titleLarge).

Constants

groundNames → const Set<String>
The names a design system gives the ground a page is drawn on: a site's surface is each of them (withSiteTheme).
inkNames → const Set<String>
The names a design system gives its ink (the color of its text): a site's onSurface is each of them that was the design system's onSurface (withSiteTheme).
none → const ThemeTokens
notationRoles → const Map<String, int>
The roles the notation draws its own parts in where a site names no design system (a hairline, a card, a table's header band, a sidebar's items at rest, a hover and a selected fill...), by name. Each has a light value, the one the notation always wrote, and a dark one made from the theme's ink and ground where the ground is dark (its luminance under 0.35): so a dark site draws them legibly, and a site with light and dark colors switches them with its mode. A color the theme names itself wins (color). Read through ThemeRefs (a document's color named line) and notationRole.
roleNames → const List<String>
The role names (resolvedRoles).