text stringlengths 1 474 |
|---|
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, |
); |
} |
}<code_end> |
<topic_end> |
<topic_start> |
Animate the list items and button |
The staggered animation plays as soon as the menu becomes visible.Start the animation in initState(). |
<code_start>@override |
void initState() { |
super.initState(); |
_createAnimationIntervals(); |
_staggeredController = AnimationController( |
vsync: this, |
duration: _animationDuration, |
)..forward(); |
}<code_end> |
Each list item slides from right to left and |
fades in at the same time.Use the list item’s Interval and an easeOut |
curve to animate the opacity and translation |
values for each list item. |
<code_start>List<Widget> _buildListItems() { |
final listItems = <Widget>[]; |
for (var i = 0; i < _menuTitles.length; ++i) { |
listItems.add( |
AnimatedBuilder( |
animation: _staggeredController, |
builder: (context, child) { |
final animationPercent = Curves.easeOut.transform( |
_itemSlideIntervals[i].transform(_staggeredController.value), |
); |
final opacity = animationPercent; |
final slideDistance = (1.0 - animationPercent) * 150; |
return Opacity( |
opacity: opacity, |
child: Transform.translate( |
offset: Offset(slideDistance, 0), |
child: child, |
), |
); |
}, |
child: Padding( |
padding: const EdgeInsets.symmetric(horizontal: 36, vertical: 16), |
child: Text( |
_menuTitles[i], |
textAlign: TextAlign.left, |
style: const TextStyle( |
fontSize: 24, |
fontWeight: FontWeight.w500, |
), |
), |
), |
), |
); |
} |
return listItems; |
}<code_end> |
Use the same approach to animate the opacity and |
scale of the bottom button. This time, use an |
elasticOut curve to give the button a springy effect. |
<code_start>Widget _buildGetStartedButton() { |
return SizedBox( |
width: double.infinity, |
child: Padding( |
padding: const EdgeInsets.all(24), |
child: AnimatedBuilder( |
animation: _staggeredController, |
builder: (context, child) { |
final animationPercent = Curves.elasticOut.transform( |
_buttonInterval.transform(_staggeredController.value)); |
final opacity = animationPercent.clamp(0.0, 1.0); |
final scale = (animationPercent * 0.5) + 0.5; |
return Opacity( |
opacity: opacity, |
child: Transform.scale( |
scale: scale, |
child: child, |
), |
); |
}, |
child: ElevatedButton( |
style: ElevatedButton.styleFrom( |
shape: const StadiumBorder(), |
backgroundColor: Colors.blue, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.