text stringlengths 1 474 |
|---|
), |
), |
), |
); |
} |
return listItems; |
} |
Widget _buildGetStartedButton() { |
return SizedBox( |
width: double.infinity, |
child: Padding( |
padding: const EdgeInsets.all(24), |
child: ElevatedButton( |
style: ElevatedButton.styleFrom( |
shape: const StadiumBorder(), |
backgroundColor: Colors.blue, |
padding: const EdgeInsets.symmetric(horizontal: 48, vertical: 14), |
), |
onPressed: () {}, |
child: const Text( |
'Get Started', |
style: TextStyle( |
color: Colors.white, |
fontSize: 22, |
), |
), |
), |
), |
); |
} |
}<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, |
); |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.