android - Flutter Animation-start 在第二次运行时不起作用
问题描述
在我的应用程序/游戏中,我有这个风扇,当你点击它时它会转身,然后一直持续到你再次点击。它工作正常,与curves.easein等。但是当你尝试第二次运行它(或任何高于1的数字)时,它会跳过最初的曲线开始,当我在2秒后重复运行时首先开始(所以它开始时没有所需的曲线)
按钮代码:
GestureDetector(
onTap: () {
Duration startStopTime = Duration(seconds: 3);
if(_animating) {
_rotationAnimationController.animateBack(1, duration: startStopTime, curve: Curves.easeOut);
setState(() {});
} else {
_rotationAnimationController.animateTo(1, duration: startStopTime, 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 秒钟才能启动(而且没有平滑曲线)
是的,我的应用程序很奇怪,我知道 :)
Thaks allready :)
解决方案
推荐阅读
- azure-ad-b2c - Azure AD B2C 自定义策略示例代码,用于通过 sendgrid 自定义登录验证电子邮件
- javascript - 将动态循环值作为不同的值传递到 json 中以显示在表的标题中
- google-apps-script - webapp脚本排队,直到谷歌表中的公式完成
- javascript - 试图在表结果-1中查找名为“客户”的列名的索引
- javascript - 可在移动设备上工作但不能在桌面设备上工作的目录
- apache-kafka - 如何确保多个 Kafka 拓扑对所有主题具有相同的分区分配?
- python - Plotly 条形图标题问题
- google-apps-script - Google 表格脚本:对 https://script.google.com 的请求失败,返回代码 404
- javascript - 在 javascript 中,函数、变量、类、模块……是否有代表所有这些的名称?
- r - 如何在 R 中使用 if/lessthan 语句在数据框中应用函数?