我正在尝试使容器具有从绿色到黄色来回动画的颜色。我尝试了以下操作,但它从绿色变为黄色,而不是从黄色变为绿色。
class MyAnimmmmmState extends State<MyAnimmmm> with TickerProviderStateMixin {
AnimationController animCtrl;
Animation<Color> colorAnimation;
@override
void initState() {
animCtrl = AnimationController(vsync: this, duration: Duration(seconds: 1))..repeat(reverse: true);
colorAnimation = ColorTween(begin: Colors.green, end: Colors.yellow).animate(animCtrl);
super.initState();
}
@override
Widget build(BuildContext context) {
return
AnimatedBuilder(
animation: animCtrl,
builder: (_, __) => Container(
width: 100,
height: 100,
decoration: ShapeDecoration(shape: StadiumBorder(), color: colorAnimation.value),
child: Center(child: Text('yooosters', style: TextStyle())))),
}
我怎样才能让它来回动画?