首页 > 解决方案 > 来回动画不能在颤动中工作

问题描述

我正在尝试使容器具有从绿色到黄色来回动画的颜色。我尝试了以下,但它的动画是从绿色到黄色而不是从黄色到绿色..

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())))),
}

我怎样才能让它来回动画?

标签: flutterdart

解决方案


推荐阅读