Animated and Ticker: a value over time
Two elements that draw nothing themselves but change a variable over time ; whatever reads that variable does the drawing.
-
Animatedsmoothly drives a number from one value to another — on an event or in an endless loop. -
Tickercalls a handler once per given interval — a timer, a countdown, a slide change.
Do not confuse them with their neighbours:
| Element | What it does |
|---|---|
Animated
(this page)
|
Publishes a smoothly changing number into an
@
variable; ordinary widgets read it and are rebuilt on every frame
|
| `*Animated` |
The same driver for
*
primitives: the value goes straight to drawing, and elements are repainted without a rebuild. Use it for charts and dashboards
|
| `Animation` |
A wrapper with
scale
/
opacity
parameters: it smoothly brings them to the new value itself. Exposes no variable
|
| `AnimatedContainer`, `AnimatedOpacity`… | Smoothly change THEIR OWN parameters; expose no variable |
Animated
Drives the output variable
value:@name
and gives it to all descendants:
{name}
or
$name
. There are three modes; the one whose parameter is set is used:
-
of:— watches a value and on every change smoothly drives the output from what is shown to the new value. The most common case: a counter, a gauge, smoothing. -
controller:— commands:forward,reverse,stop,reset,fromStartToEnd,fromEndToStart, or a number — a target in thefrom..torange. -
loop:true— an endlessfrom → toloop from the first frame, without any event: a marquee, a "breathing" card, rotation.
Type:
wrapper
@progress:0.0
Column spacing:8
Animated of:$progress value:@shown duration:600 curve:easeOutCubic
Text $"${round(shown * 100)}%"
FilledButton onPressed:{progress = progress + 0.25}
Text "More"
| Parameter | Type | Default | Description |
|---|---|---|---|
value
|
@
variable
|
— |
Where to write the current value. Declared right here:
value:@t
. Without it the element does nothing
|
of
|
number / list of numbers | — |
of:
mode: the value to watch. A change (by value) starts a new transition from what is shown
|
controller
|
number / string | — |
Command mode: a number is a target (in
from..to
), a string is a command. Write it as a variable:
controller:$mode
|
loop
|
bool | false |
Loop mode:
from → to
and from the start again, endlessly.
controller:
is not read then
|
delay
|
int (ms) | 0 |
Only for
loop:
: a pause before the first cycle; a
negative
one says from which point of the cycle to start (
delay:-1000
with
duration:4000
— from a quarter). Like CSS
animation-delay
|
paused
|
bool | false |
Only for
loop:
: holds the loop in place;
false
— continue from the same phase
|
from
|
double | 0 |
Start of the range for
controller:
and
loop:
|
to
|
double | 1 | End of the range |
duration
|
int (ms) |
400 with
of:
, otherwise 600
|
Duration of a transition or of one cycle —
as a number of milliseconds
:
duration:600
|
curve
|
string |
easeOut
|
Curve:
linear
,
easeIn
,
easeInOut
,
easeOutCubic
,
easeOutBack
,
elasticOut
,
bounceOut
… An unknown name gives
easeOut
. In
loop:
it sets the shape of each cycle
|
of:
— smoothly to a new value
A number that changes in jumps becomes smooth. This is how you smooth anything driven by
`PointerData`
: without
Animated
the element jerks after the mouse.
@score:0
Column spacing:8
Animated of:$score value:@n duration:800 curve:easeOutCubic
Text $"${round(n)} points"
#style fontSize:32 fontWeight:bold
FilledButton onPressed:{score = score + 100}
Text "+100"
loop:
— motion over time
Column spacing:16
Animated loop:true value:@t duration:3000 curve:linear
Transform rotate:{t * 6.2832}
Icon autorenew size:48 color:0xFF4F46E5
Hovered hovered:@over
Animated loop:true value:@p duration:2000 curve:easeInOut paused:$over
Opacity opacity:{0.3 + 0.7 * p}
Text "Hover to stop the pulse"
controller:
— on command
@mode:"reverse"
Column spacing:8
Animated controller:$mode value:@w from:40 to:240 duration:500 curve:easeOutCubic
SizedBox width:$w height:24
ColoredBox color:0xFF4F46E5
FilledButton onPressed:{mode = mode == "forward" ? "reverse" : "forward"}
Text "Back and forth"
Write the command as a variable (
controller:$mode
): the element subscribes to it and executes every new command. An expression (
controller:{…}
) is read once — when the element appears.
Ticker
A timer: calls
onTick
once per
duration
. The handler returns whether to continue: the last expression of the body is
true
to keep ticking, anything else stops it.
Type:
wrapper
@seconds:0
Column spacing:8
Ticker duration:1s notifier:$seconds onTick:{seconds = seconds - 1; seconds > 0}
Text $"Resend in ${seconds} s"
FilledButton onPressed:{seconds = 30}
Text "Send code"
| Parameter | Type | Default | Description |
|---|---|---|---|
duration
|
Duration |
1s
|
Interval between calls:
500ms
,
1s
|
onTick
|
callback | — |
The body called on every tick; if its last value is
true
, it continues
|
notifier
|
variable | — | In the app: every change of this variable (re)starts the timer |
The child is drawn as is; without a child
Ticker
takes up no space.
When the timer starts differs between the app and the site:
-
In the app
the timer starts when the
notifier:variable changes, and restarts on each of its changes. Withoutnotifier:it never starts. -
On the site
the timer starts once when the page loads;
notifier:is not read. A countdown started by a button (the example above) will not run on the site: the timer fires on load and stops.
Hence: a countdown on a button is for the app; for the site — something that ticks from the moment the page opens (rotating quotes, a clock).
Differences between the app and the site
-
Animated of:— on the site the number runs the same way, with the same curve and duration. -
Animated loop:— on the site the cycle follows thecurve:curve approximately (by 11 points per cycle);delayandpausedwork the same. -
Animated controller:is not driven on the site: the output stays at its initial value, and commands are not executed. -
Ticker— see above: on the site it starts on load,notifier:is not read. -
"Reduce motion" in the system: in the app a
loop:cycle does not start (the value stays in place); on the site animations are shortened to instant.
See also
- Implicit animations — smooth change of one element's parameters
-
Transitions and Hero
—
FadeTransition/SlideTransition/… that readAnimated -
Pointer and touch
—
HoveredandPointerDataas sources forAnimated -
`*Animated`
— the same driver for
*primitives -
Animation
— smooth
scale/opacityin one wrapper - Motion: scene and time — a film with a clock, keyframes and layers