text stringlengths 1 372 |
|---|
); |
} |
} |
<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, |
padding: const EdgeInsets.symmetric(horizontal: 48, vertical: 14), |
), |
onPressed: () {}, |
child: const text( |
'get started', |
style: TextStyle( |
color: colors.white, |
fontSize: 22, |
), |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.