Theme
Overrides the theme
for its subtree
. Without
mode
it is a Material theme on top of the inherited one: the colors you set are replaced, everything else stays as it was. With
mode
the subtree's project theme (
$theme.*
) is also switched to the named one, without touching the person's choice.
Type:
wrapper
Theme mode:"dark"
ColoredBox color:{theme.backgroundPage ?? "#FF111111"}
Padding
#padding all 24
Text "This block is always dark"
The
$theme
tokens themselves, the
data/theme/<mode>.json
files and switching with
theme.set(…)
are described in
"Theming and localization"
; this page covers only the element.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
mode
|
string | — |
Name of the project theme (
light
,
dark
or your own — by its file in
data/theme/
) that
$theme.*
reads inside. The person's choice (
theme.set
) does not change. An unknown name keeps the surrounding theme, with a diagnostic. Can be an expression:
mode:{lit ? "light" : "dark"}
|
brightness
|
light
|
dark
|
— |
Brightness of the subtree's Material theme. With
mode
and no
brightness
, the named theme's brightness is used
|
#colorScheme
|
structure | — | Material color scheme, see below |
primaryColor
|
color | — | The theme's primary color |
primaryColorDark
|
color | — | Dark variant of the primary color |
primaryColorLight
|
color | — | Light variant of the primary color |
canvasColor
|
color | — | Material "canvas" background |
cardColor
|
color | — | Card background |
scaffoldBackgroundColor
|
color | — |
Scaffold
background
|
dividerColor
|
color | — | Divider color |
disabledColor
|
color | — | Color of disabled elements |
hintColor
|
color | — | Color of hints in fields |
focusColor
|
color | — | Highlight on focus |
hoverColor
|
color | — | Highlight on hover |
highlightColor
|
color | — | Highlight on press |
splashColor
|
color | — | Color of the press "ripple" |
shadowColor
|
color | — | Shadow color |
secondaryHeaderColor
|
color | — | Color of secondary headers |
unselectedWidgetColor
|
color | — | Color of unselected checkboxes and switches |
applyElevationOverlayColor
|
bool | — | Lighten elevated surfaces in a dark theme |
Parameters that are not set do not change the inherited theme.
Nested structures
#colorScheme
The Material color scheme that buttons, fields and switches are painted with. It
does not merge
with the inherited scheme: its base is the standard light or dark Material scheme (by
brightness
inside
#colorScheme
), with the given colors laid on top. With the positional
fromSeed
the base is built from
seedColor
.
@taps:0
Theme
#colorScheme fromSeed seedColor:0xFF4F46E5 brightness:dark
FilledButton onPressed:{taps = taps + 1}
Text "A button in its own scheme"
| Parameter | Type | Default | Description |
|---|---|---|---|
| (positional) |
fromSeed
|
— |
Build the scheme from
seedColor
|
seedColor
|
color | blue |
Source color for
fromSeed
|
brightness
|
light
|
dark
|
light
|
Base of the scheme |
primary
,
onPrimary
,
primaryContainer
,
onPrimaryContainer
|
color | — | The primary color and colors on it |
primaryFixed
,
primaryFixedDim
,
onPrimaryFixed
,
onPrimaryFixedVariant
|
color | — | Fixed variants of the primary color |
secondary
,
onSecondary
,
secondaryContainer
,
onSecondaryContainer
|
color | — | The secondary color |
secondaryFixed
,
secondaryFixedDim
,
onSecondaryFixed
,
onSecondaryFixedVariant
|
color | — | Fixed variants of the secondary color |
tertiary
,
onTertiary
,
tertiaryContainer
,
onTertiaryContainer
|
color | — | The tertiary color |
tertiaryFixed
,
tertiaryFixedDim
,
onTertiaryFixed
,
onTertiaryFixedVariant
|
color | — | Fixed variants of the tertiary color |
error
,
onError
,
errorContainer
,
onErrorContainer
|
color | — | Error colors |
surface
,
onSurface
,
onSurfaceVariant
,
surfaceDim
,
surfaceBright
,
surfaceTint
|
color | — | Surfaces |
surfaceContainerLowest
,
surfaceContainerLow
,
surfaceContainer
,
surfaceContainerHigh
,
surfaceContainerHighest
|
color | — | Surface containers |
outline
,
outlineVariant
,
shadow
,
scrim
|
color | — | Outlines, shadows, scrim |
inverseSurface
,
onInverseSurface
,
inversePrimary
|
color | — | Inverse colors |
Examples
A dark section on a light site
mode
says what the
place
looks like;
theme.set
says what the
person
prefers. A section that has to stay dark on a light page is the former:
Column
Text "The light part"
Theme mode:"dark"
ColoredBox color:{theme.backgroundPage ?? "#FF111111"}
Padding
#padding all 24
Text "Dark section"
#style color:{theme.textPrimary ?? "#FFFFFFFF"}
Theme from state
@lit:true
Theme mode:{lit ? "light" : "dark"}
Switch value:$lit onChanged:(value){lit = value}
A Material accent for one block
@sure:false
Theme
#colorScheme primary:0xFFE11D48 onPrimary:0xFFFFFFFF
Row spacing:8
Checkbox value:$sure onChanged:(value){sure = value}
FilledButton onPressed:{sure = false}
Text "Delete"
Differences between the app and the site
-
The site understands
only
mode: the subtree switches to the named theme without an extra wrapper, and the$theme.*tokens inside come from it. A reactivemodeswitches the theme right in the browser. -
Without
modethe site draws only the child:brightness,#colorSchemeand all the Material theme colors are not applied. Buttons and fields on the site are painted with$themetokens, not with the element's Material scheme.
See also
-
Theming and localization
—
$theme,data/theme/,theme.set -
Switch
,
Checkbox
— controls that
#colorSchemepaints