text stringlengths 1 372 |
|---|
); |
} |
} |
<code_end> |
<topic_end> |
<topic_start> |
prepare for animations |
control of the animation timing requires an |
AnimationController. |
add the SingleTickerProviderStateMixin |
to the MenuState class. then, declare and |
instantiate an AnimationController. |
<code_start> |
class _MenuState extends State<Menu> with SingleTickerProviderStateMixin { |
late AnimationController _staggeredController; |
@override |
void initState() { |
super.initState(); |
_staggeredController = AnimationController( |
vsync: this, |
); |
} |
} |
@override |
void dispose() { |
_staggeredController.dispose(); |
super.dispose(); |
} |
} |
<code_end> |
the length of the delay before every animation is |
up to you. define the animation delays, |
individual animation durations, and the total |
animation duration. |
<code_start> |
class _MenuState extends State<Menu> with SingleTickerProviderStateMixin { |
static const _initialDelayTime = duration(milliseconds: 50); |
static const _itemSlideTime = duration(milliseconds: 250); |
static const _staggerTime = duration(milliseconds: 50); |
static const _buttonDelayTime = duration(milliseconds: 150); |
static const _buttonTime = duration(milliseconds: 500); |
final _animationDuration = _initialDelayTime + |
(_staggertime * _menuTitles.length) + |
_buttonDelayTime + |
_buttonTime; |
} |
<code_end> |
in this case, all the animations are delayed by 50 ms. |
after that, list items begin to appear. |
each list item’s appearance is delayed by 50 ms after the |
previous list item begins to slide in. |
each list item takes 250 ms to slide from right to left. |
after the last list item begins to slide in, |
the button at the bottom waits another 150 ms to pop in. |
the button animation takes 500 ms. |
with each delay and animation duration defined, |
the total duration is calculated so that it can be |
used to calculate the individual animation times. |
the desired animation times are shown in the following diagram: |
to animate a value during a subsection of a larger animation, |
flutter provides the interval class. |
an interval takes a start time percentage and an end |
time percentage. that interval can then be used to |
animate a value between those start and end times, |
instead of using the entire animation’s start and |
end times. for example, given an animation that takes 1 second, |
an interval from 0.2 to 0.5 would start at 200 ms |
(20%) and end at 500 ms (50%). |
declare and calculate each list item’s interval and the |
bottom button interval. |
<code_start> |
class _MenuState extends State<Menu> with SingleTickerProviderStateMixin { |
final List<Interval> _itemSlideIntervals = []; |
late interval _buttonInterval; |
@override |
void initState() { |
super.initState(); |
_createAnimationIntervals(); |
_staggeredController = AnimationController( |
vsync: this, |
duration: _animationDuration, |
); |
} |
void _createAnimationIntervals() { |
for (var i = 0; i < _menuTitles.length; ++i) { |
final startTime = _initialDelayTime + (_staggertime * i); |
final endTime = startTime + _itemSlideTime; |
_itemSlideIntervals.add( |
interval( |
startTime.inMilliseconds / _animationDuration.inMilliseconds, |
endTime.inMilliseconds / _animationDuration.inMilliseconds, |
), |
); |
} |
final buttonStartTime = |
duration(milliseconds: (_menutitles.length * 50)) + _buttonDelayTime; |
final buttonEndTime = buttonStartTime + _buttonTime; |
_buttonInterval = interval( |
buttonStartTime.inMilliseconds / _animationDuration.inMilliseconds, |
buttonEndTime.inMilliseconds / _animationDuration.inMilliseconds, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.