text
stringlengths
1
372
architecture
animations are actually built from a number of core building blocks.
<topic_end>
<topic_start>
scheduler
the SchedulerBinding is a singleton class
that exposes the flutter scheduling primitives.
for this discussion, the key primitive is the frame callbacks.
each time a frame needs to be shown on the screen,
flutter’s engine triggers a “begin frame” callback that
the scheduler multiplexes to all the listeners registered using
scheduleFrameCallback(). all these callbacks are
given the official time stamp of the frame, in
the form of a duration from some arbitrary epoch. since all the
callbacks have the same time, any animations triggered from these
callbacks will appear to be exactly synchronised even
if they take a few milliseconds to be executed.
<topic_end>
<topic_start>
tickers
the ticker class hooks into the scheduler’s
scheduleFrameCallback()
mechanism to invoke a callback every tick.
a ticker can be started and stopped. when started,
it returns a future that will resolve when it is stopped.
each tick, the ticker provides the callback with the
duration since the first tick after it was started.
because tickers always give their elapsed time relative to the first
tick after they were started; tickers are all synchronised. if you
start three tickers at different times between two ticks, they will all
nonetheless be synchronised with the same starting time, and will
subsequently tick in lockstep. like people at a bus-stop,
all the tickers wait for a regularly occurring event
(the tick) to begin moving (counting time).
<topic_end>
<topic_start>
simulations
the simulation abstract class maps a
relative time value (an elapsed time) to a
double value, and has a notion of completion.
in principle simulations are stateless but in practice
some simulations (for example,
BouncingScrollSimulation and
ClampingScrollSimulation)
change state irreversibly when queried.
there are various concrete implementations
of the simulation class for different effects.
<topic_end>
<topic_start>
animatables
the animatable abstract class maps a
double to a value of a particular type.
animatable classes are stateless and immutable.
<topic_end>
<topic_start>
tweens
the Tween<T> abstract class maps a double
value nominally in the range 0.0-1.0 to a typed value
(for example, a color, or another double).
it is an animatable.
it has a notion of an output type (t),
a begin value and an end value of that type,
and a way to interpolate (lerp) between the begin
and end values for a given input value (the double nominally in
the range 0.0-1.0).
tween classes are stateless and immutable.
<topic_end>
<topic_start>
composing animatables
passing an animatable<double> (the parent) to an animatable’s
chain() method creates a new animatable subclass that applies the
parent’s mapping then the child’s mapping.
<topic_end>
<topic_start>
curves
the curve abstract class maps doubles
nominally in the range 0.0-1.0 to doubles
nominally in the range 0.0-1.0.
curve classes are stateless and immutable.
<topic_end>
<topic_start>
animations
the animation abstract class provides a
value of a given type, a concept of animation
direction and animation status, and a listener interface to
register callbacks that get invoked when the value or status change.
some subclasses of animation have values that never change
(kalwayscompleteanimation, kAlwaysDismissedAnimation,
AlwaysStoppedAnimation); registering callbacks on
these has no effect as the callbacks are never called.
the animation<double> variant is special because it can be used to
represent a double nominally in the range 0.0-1.0, which is the input
expected by curve and tween classes, as well as some further
subclasses of animation.
some animation subclasses are stateless,
merely forwarding listeners to their parents.
some are very stateful.
<topic_end>
<topic_start>
composable animations