flutter - TweenSequence 忽略 TweenSequence 项
问题描述
嗨,我想在我的 Flutter 应用程序中不断地淡入淡出图像。为此,我使用 TweenSequence:
AnimationController animationController;
Animation<double> opacityAnimation;
double opacity = 0.5;
@override
void initState() {
super.initState();
animationController =
AnimationController(vsync: this, duration: Duration(seconds: 3));
opacityAnimation = TweenSequence(
[
TweenSequenceItem<double>(
tween: Tween<double>(begin: 0.5, end: 1.0).chain(
CurveTween(curve: Curves.bounceIn),
),
weight: 50),
TweenSequenceItem<double>(
tween: Tween<double>(begin: 1.0, end: 0.5).chain(
CurveTween(curve: Curves.bounceIn),
),
weight: 50),
],
).animate(animationController);
animationController.addListener(
() {
setState(() {
opacity = animationController.value;
print(opacity);
});
},
);
animationController.repeat();
}
@override
void dispose() {
animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Center(
child: Stack(
children: [
Image.asset("assets/images/buildup_0.png"),
Opacity(
child: Image.asset("assets/images/Logo_K.png"),
opacity: opacity,
),
],
),
);
}
}
但是,动画只是忽略了我给它的 Tweens 并在 0 和 1 之间进行动画处理,然后跳回到 0 并重复。由于打印语句,我可以在控制台中看到这一点。我在这里遗漏了一些明显的东西吗?
解决方案
我刚刚找到了解决方案:我需要将其设置为 opacityAnimation.value 而不是将 opacity 设置为 animationController.value
推荐阅读
- c# - C#如何复制Excel中的每一行
- c++ - Cmake 无法使用 lmdb.h 编译 Caffe
- node.js - 如何在节点 js 中使用 postman 将数据发布到 .json 文件
- elasticsearch - Elasticsearch:在关键字中搜索忽略大小写和重音(通过聚合)
- jenkins - 从另一个 Jenkinsfile 运行一个 Jenkinsfile
- php - 为什么在 Laravel 5.6 的编辑视图文件中没有更新图像?
- laravel - 我的 Laravel 雄辩查询有什么问题
- events - Java 事件过滤器占用多少内存?
- git - 相关变更集的 Git 工作流程
- angular - Angular 5 / Jasmine 2 测试 setTimeout 函数只有一次