我可以在 AnimationStatus.completed 之后再次转发相同的 animationController 吗

can I forward same animationController again after AnimationStatus.completed

我想在动画状态完成时让同一个animationController forward,setState更新补间动画中的值,这样第二个animationController forward会实现不同的动画,可以吗?谢谢!

GestureDetector(
    
        onTap: () {
          if (firstController.status == AnimationStatus.dismissed) {
            firstController.forward();
          } else if (firstController.status == AnimationStatus.completed) {
            setState(() {

              double firstOpacity = 1.0;  //new value
              double secondOpacity = 0.7;//new value
              double thirdOpacity = 0.4;//new value
            });
            firstController.forward();  // now it does not work
          }
        },
        child: Center(
          child: Container(
            child: AnimatedBuilder(
              animation: firstController,
              builder: _buildAnimation,
            ),
          ),
        ),
      ),

你可以做到这一点,甚至更多! This api article talks about staggered animations 在这里你可以设置整个动画的间隔百分比到你的特定动画。 Interval 部分是您设置这些值的地方。

width = Tween<double>(
  begin: 50.0,
  end: 150.0,
).animate(
  CurvedAnimation(
    parent: controller,
    curve: Interval(
      0.125, 0.250,
      curve: Curves.ease,
    ),
  ),
);

关于 AnimationController,您有一些方法可以提供帮助,查看 this api article about them 并搜索 repeatresetreverse 方法并查看你拥有的参数。您可以使用 Flutter 做很多事情。

编辑:

如果你想制作一个在继续之前暂停的 1/3 动画,你可以这样做:

    final animationController = AnimationController(vsync: this);
    final animation = Tween<double>(begin: 0, end: 0).animate(
      CurvedAnimation(
        parent: animationController,
        curve: const Interval(
          0,
          1 / 3,
          curve: Curves.easeIn,
        ),
      ),
    );
    animation.addStatusListener((status) {
      animationController.stop(); // For example, but read the documentation about the stop method
    });

我希望你能从这些links和代码中得到启发。

  late Animation<double> _animation;
  late AnimationController _animationController;
  @override
  void initState() {
    super.initState();
    _animationController = AnimationController(
        vsync: this,
        duration: const Duration(milliseconds: 1500),
        reverseDuration: const Duration(milliseconds: 1500))
      ..forward();
    _animationController.addListener(() {
      if (_animationController.isCompleted) {
        _animationController.reverse();
      } else if (_animationController.isDismissed) {
        _animationController.forward();
      }
      setState(() {});
    });
    _animation =
        CurvedAnimation(parent: _animationController, curve: Curves.easeInOut);
    _animation = Tween(begin: -.6, end: .4).animate(_animation);
  }