Filters and masks
Wrappers that change how the child is drawn: recolor it, blur the child itself or what shows through it, lay a gradient over its shape. They do not change the layout.
| Task | Element |
|---|---|
| Make a picture grey, tint an icon | ColorFiltered |
| Soft glow, a blurred background blob | ImageFiltered — blurs the child itself |
| "Frosted glass" over content | BackdropFilter — blurs what is under the child |
| Gradient text, a fading edge | ShaderMask |
ColorFiltered
Passes the child's painting through a color filter.
Type:
single-child
ColorFiltered
#colorFilter saturation 0
ColoredBox color:0xFF4F46E5
SizedBox width:80 height:80
| Parameter | Type | Default | Description |
|---|---|---|---|
#colorFilter
|
structure | — | The filter, see below. Without it the child is drawn as is |
#colorFilter
The first positional argument is the kind of filter:
| Kind | Parameters | What it does |
|---|---|---|
mode
|
color
(red by default),
blendMode
(
src
by default)
|
Blends the child's painting with the color in the given mode.
srcATop
— recolor the child by its shape,
multiply
— darken with the color
|
matrix
|
#matrix
— 20 numbers, a 4×5 matrix by rows (R, G, B, A)
|
An arbitrary color transform |
saturation
|
second positional — a number, 0 by default |
Saturation:
0
— grey,
1
— unchanged
|
linearToSrgbGamma
|
— | Conversion from linear color to sRGB |
srgbToLinearGamma
|
— | The reverse conversion |
ColorFiltered
#colorFilter mode color:0xFF4F46E5 blendMode:srcATop
Icon star size:48
ColorFiltered
#colorFilter matrix
#matrix 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0
ColoredBox color:0xFF059669
SizedBox width:80 height:80
blendMode
blend modes:
clear
,
src
,
dst
,
srcOver
,
dstOver
,
srcIn
,
dstIn
,
srcOut
,
dstOut
,
srcATop
,
dstATop
,
xor
,
plus
,
modulate
,
screen
,
overlay
,
darken
,
lighten
,
colorDodge
,
colorBurn
,
hardLight
,
softLight
,
difference
,
exclusion
,
multiply
,
hue
,
saturation
,
color
,
luminosity
.
ImageFiltered
Blurs the child itself . A solid shape with a large blur becomes a soft glow — something a gradient imitates only from a distance.
Type:
single-child
ImageFiltered sigmaX:40 sigmaY:40
Container width:200 height:200
#decoration color:0x996938EF
#borderRadius circular 999
| Parameter | Type | Default | Description |
|---|---|---|---|
sigmaX
|
double | 0 | Horizontal blur strength, in logical pixels |
sigmaY
|
double | 0 | Vertical blur strength |
tileMode
|
string | decal |
What lies past the edge of the painting when blurring:
decal
(transparent),
clamp
,
repeated
,
mirror
|
enabled
|
bool | true |
false
draws the child without blur and
keeps it in the tree
— its state is not lost
|
BackdropFilter
Blurs what shows through the child — the "frosted glass" of a header over a scrolling page. The child itself is not blurred; usually it is a semi-transparent fill with text.
Type:
single-child
Stack
Row
ColoredBox color:0xFF4F46E5
SizedBox width:120 height:120
ColoredBox color:0xFFF59E0B
SizedBox width:120 height:120
Positioned left:60 top:30
ClipRRect
#borderRadius circular 16
BackdropFilter sigmaX:12 sigmaY:12 saturate:1.5
ColoredBox color:0x66FFFFFF
SizedBox width:120 height:60
Center
Text "Glass"
| Parameter | Type | Default | Description |
|---|---|---|---|
sigmaX
|
double | 0 | Horizontal blur strength |
sigmaY
|
double | 0 | Vertical blur strength |
saturate
|
double | — |
Saturation of what shows through:
1
— as is,
1.5
— more vivid,
0
— grey. Applied after the blur
|
blendMode
|
string | srcOver |
How the blurred background blends with what is under it (the list of modes is under
ColorFiltered
)
|
The blur captures everything under the element up to the nearest clip (without one — up to the edge of the window), so
BackdropFilter
is almost always wrapped in
ClipRRect
— it limits the glass to a shape.
ShaderMask
Lays a gradient over the child in the given blend mode. With
srcIn
the gradient is visible only where the child is painted — that is how gradient text is made; with
dstIn
the gradient works as an opacity mask — that is how a fading edge is made.
Type:
single-child
Column spacing:16
ShaderMask blendMode:srcIn
#gradient linear begin:centerLeft end:centerRight
#colors 0xFF4F46E5 0xFFDB2777
Text "Gradient heading"
#style fontSize:32 fontWeight:bold
ShaderMask blendMode:dstIn
#gradient linear begin:topCenter end:bottomCenter
#colors 0xFF000000 0x00000000
ColoredBox color:0xFF059669
SizedBox width:200 height:80
| Parameter | Type | Default | Description |
|---|---|---|---|
#gradient
|
structure | — |
Gradient:
linear
,
radial
or
sweep
with
#colors
— as on
DecoratedBox
. Without it the child is drawn as is
|
blendMode
|
string | modulate |
Blend mode of the gradient with the child (the list is under
ColorFiltered
)
|
Differences between the app and the site
-
ColorFiltered -
saturation N→ CSSfilter: saturate(N)— as in the app. -
matrix→ alwaysfilter: grayscale(1), whatever numbers are in#matrix. A matrix other than grey gives grey on the site. -
modewithsrcATop/srcIn→ a color layer over the whole box of the child, not by its shape: an icon on a transparent background becomes a colored rectangle. -
modewith separable modes (multiply,screen, …) → a color layer over the whole window (position: fixed) withmix-blend-mode. -
linearToSrgbGamma,srgbToLinearGamma— not carried over, the child is drawn as is. -
ImageFiltered→ CSSfilter: blur(). CSS has one radius: with differentsigmaXandsigmaYsigmaXis taken, and the editor warns about it.tileModeis not read.enabled:false— the child without the filter. -
BackdropFilter→ CSSbackdrop-filter: blur() saturate(). With differentsigmaXandsigmaYtheir average is taken.blendModeis not read. -
ShaderMask -
srcIn/srcATopover text → gradient text (background-clip: text) — as in the app. -
dstIn→mask-imagewith the gradient,dstOut→ the inverted mask — as in the app. - Other combinations → a gradient layer over the child's box (by the rectangle, not by the shape).
See also
- Opacity — opacity as a whole
- DecoratedBox — gradients and shadows as a background
-
ClipRRect
— limit the
BackdropFilterglass to a shape - Image — a picture that is often recolored