【问题标题】:How to make animation value always run from 0 to 1如何让动画值始终从0运行到1
【发布时间】:2022-11-22 22:33:50
【问题描述】:

我正在尝试创建一个从 0 到 1 的补间动画:

final Tween<double> _tween = Tween(begin: 0, end: 1);

late AnimationController _controller;

late Animation<double> _animation;

出于某种原因,有时我需要调用 _controller.reverse()_controller.forward(),而我的 animation.value 从 0 运行到 1,然后从 1 运行到 0。

我如何始终让animation.value从 0 运行到 1?

【问题讨论】:

    标签: flutter dart flutter-animation


    【解决方案1】:

    您可以使用.repeat()

    _controller.repeat();
    

    如果你喜欢在重复时倒转

    _controller.repeat(reverse: true);
    

    此外,只是为了进入初始状态,您可以使用

    _controller.reset();
    

    然后就可以开始了

    _controller.forward();
    

    【讨论】:

    • 还要检查_controller.forward(from: 0);
    猜你喜欢
    • 2015-07-10
    • 1970-01-01
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多