老孟导读:在前面的文章中介绍了 《Flutter 动画系列》25种动画组件超全总结 "http://laomengit.com/flutter/module/animated_1/"
Animation _sizeAnimation = Tween(begin: 100.0,end: 300.0).animate(CurvedAnimation(
parent: _animationController,curve: Interval(0.5,1.0)));
class AnimationDemo extends StatefulWidget {
@override
State<StatefulWidget> createState() => _AnimationDemo();
}
class _AnimationDemo extends State<AnimationDemo>
with SingleTickerProviderStateMixin {
AnimationController _animationController;
Animation _colorAnimation;
Animation _sizeAnimation;
@override
void initState() {
_animationController =
AnimationController(duration: Duration(seconds: 5),vsync: this)
..addListener((){setState(() {
});});
_colorAnimation = ColorTween(begin: Colors.red,end: Colors.blue).animate(
CurvedAnimation(
parent: _animationController,curve: Interval(0.0,0.5)));
_sizeAnimation = Tween(begin: 100.0,end: 300.0).animate(CurvedAnimation(
parent: _animationController,1.0)));
//开始动画
_animationController.forward();
super.initState();
}
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,children: <Widget>[
Container(
height: _sizeAnimation.value,width: _sizeAnimation.value,color: _colorAnimation.value),],),);
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
}
我们也可以设置同时动画,只需将2个
Interval
的值都改为
Interval(0.0,1.0)
。
_animation = TweenSequence([
TweenSequenceItem(
tween: Tween(begin: 100.0,end: 200.0)
.chain(CurveTween(curve: Curves.easeIn)),weight: 40),TweenSequenceItem(tween: ConstantTween<double>(200.0),weight: 20),TweenSequenceItem(tween: Tween(begin: 200.0,end: 300.0),]).animate(_animationController);