Flutter Animation-开始无法在第二次运行

问题描述

在我的应用/游戏中,我有这个风扇,当您单击它时它会旋转,然后一直持续到您再次单击。它可以正常工作,带有curve.easein等。 但是,当您尝试第二次运行(或与此相关的任何大于1的数字)时,它将跳过最初的曲线起点,而当我运行 repeat 时首先开始> 2秒后(因此开始时没有所需的曲线)

按钮代码:

GestureDetector(
                       onTap: () {
                         Duration startStopTime = Duration(seconds: 3);
                         if(_animating) {
                           _rotationAnimationController.animateBack(1,duration: startStopTime,curve: Curves.easeOut);
                           setState(() {});
                         } else {
                           _rotationAnimationController.animateTo(1,curve: Curves.easeInCubic);
                           Future.delayed(startStopTime,() {
                             _rotationAnimationController.repeat();
                           });
                         }
                         setState(() {
                           _animating = !_animating;
                         });
                       },child: Padding(
                         padding: const EdgeInsets.only(top: 70),child: Container(
                           color: Colors.blue[300],width: MediaQuery.of(context).size.width/6*5,height: MediaQuery.of(context).size.width/6*5,),

风扇小部件:

IgnorePointer(
                       child: Container(
                         child: Transform.rotate(
                           angle: _animation.value,child: Image.asset('assets/FanArms.png')
                         ),

动画:

 var _animating = false;

  AnimationController _rotationAnimationController;
  Animation<double> _animation;

  @override
  void initState() {
    super.initState();
    _rotationAnimationController = AnimationController(
      duration: Duration(milliseconds: 2000),vsync: this,);
    _animation =
        Tween<double>(begin: 0,end: 4 * pi ).animate(_rotationAnimationController)
      ..addListener(() {
        setState(() {});
      });
  }

  @override
  void dispose() {
    _rotationAnimationController.dispose();
    super.dispose();
  }

这是我的应用中的粉丝的视频 https://imgur.com/a/wtxFNvL

  • 当风扇停止运转时,我再次单击它,它大约需要3秒钟才能开始运行(而且没有平滑的曲线)

是的,我的应用很奇怪,我知道:)

已准备就绪:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...