text
stringlengths
1
372
_runAnimation(details.velocity.pixelsPerSecond, size);
},
child: align(
alignment: _dragAlignment,
child: card(
child: widget.child,
),
),
);
}
}
<code_end>
<topic_end>
<topic_start>
staggered animations
<topic_end>
<topic_start>
what you'll learn
terminology:
if the concept of tweens or tweening is new to you, see the
animations in flutter tutorial.
staggered animations are a straightforward concept: visual changes
happen as a series of operations, rather than all at once.
the animation might be purely sequential, with one change occurring after
the next, or it might partially or completely overlap. it might also
have gaps, where no changes occur.
this guide shows how to build a staggered animation in flutter.
<topic_end>
<topic_start>
examples
this guide explains the basic_staggered_animation example.
you can also refer to a more complex example,
staggered_pic_selection.
the following video demonstrates the animation performed by
basic_staggered_animation:
in the video, you see the following animation of a single widget,
which begins as a bordered blue square with slightly rounded corners.
the square runs through changes in the following order:
after running forward, the animation runs in reverse.
new to flutter?
this page assumes you know how to create a layout using flutter’s
widgets. for more information, see building layouts in flutter.
<topic_end>
<topic_start>
basic structure of a staggered animation
<topic_end>
<topic_start>
what's the point?
the following diagram shows the intervals used in the
basic_staggered_animation example.
you might notice the following characteristics:
to set up the animation:
when the controlling animation’s value changes,
the new animation’s value changes, triggering the UI to update.
the following code creates a tween for the width property.
it builds a CurvedAnimation,
specifying an eased curve. see curves for
other available pre-defined animation curves.
the begin and end values don’t have to be doubles.
the following code builds the tween for the borderRadius property
(which controls the roundness of the square’s corners),
using BorderRadius.circular().
<topic_end>
<topic_start>
complete staggered animation
like all interactive widgets, the complete animation consists
of a widget pair: a stateless and a stateful widget.
the stateless widget specifies the tweens,
defines the animation objects, and provides a build() function
responsible for building the animating portion of the widget tree.
the stateful widget creates the controller, plays the animation,
and builds the non-animating portion of the widget tree.
the animation begins when a tap is detected anywhere in the screen.
full code for basic_staggered_animation’s main.dart
<topic_end>
<topic_start>
stateless widget: StaggerAnimation
in the stateless widget, StaggerAnimation,
the build() function instantiates an
AnimatedBuilder—a general purpose widget for building
animations. the AnimatedBuilder
builds a widget and configures it using the tweens’ current values.
the example creates a function named _buildAnimation() (which performs
the actual UI updates), and assigns it to its builder property.
AnimatedBuilder listens to notifications from the animation controller,
marking the widget tree dirty as values change.
for each tick of the animation, the values are updated,
resulting in a call to _buildAnimation().
<topic_end>
<topic_start>
stateful widget: StaggerDemo
the stateful widget, StaggerDemo, creates the AnimationController
(the one who rules them all), specifying a 2000 ms duration. it plays
the animation, and builds the non-animating portion of the widget tree.
the animation begins when a tap is detected in the screen.
the animation runs forward, then backward.
<topic_end>
<topic_start>
create a staggered menu animation
a single app screen might contain multiple animations.