Animation 颤振设置开始动画值
我想传入一个值,将起始动画值设置为1.0,而不是从0开始,但我不知道这是如何实现的Animation 颤振设置开始动画值,animation,flutter,dart,Animation,Flutter,Dart,我想传入一个值,将起始动画值设置为1.0,而不是从0开始,但我不知道这是如何实现的 class AnimatedIconButton extends StatefulWidget { AnimatedIconButton(this.img, this.start); final String img; final double start; @override _AnimatedIconButtonState createState() => _AnimatedIcon
class AnimatedIconButton extends StatefulWidget {
AnimatedIconButton(this.img, this.start);
final String img;
final double start;
@override
_AnimatedIconButtonState createState() => _AnimatedIconButtonState();
}
class _AnimatedIconButtonState extends State<AnimatedIconButton>
with TickerProviderStateMixin {
AnimationController _controller;
Animation _animation;
void animateButton() {
if (_animation.value == 0)
_controller.forward();
else
_controller.reverse();
}
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: Duration(milliseconds: 300),
vsync: this,
);
_animation =
CurvedAnimation(parent: _controller, curve: Curves.easeOutQuad);
_controller.addListener(() {
setState(() {});
});
_animation.value = widget.start;// does not work
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialButton(
splashColor: Colors.white,
highlightColor: Colors.white,
child: Image.asset("images/${widget.img}.png",
width: 33 + (16 * _animation.value)),
onPressed: () {
animateButton();
},
);
}
}
您可以使用:
_controller.forward(from: 0.0);
或
并设置您需要的值
或用于设置初始值,您可以使用
_controller.value = widget.start;
您可以使用:
_controller.forward(from: 0.0);
或
并设置您需要的值
或用于设置初始值,您可以使用
_controller.value = widget.start;
在代码中:
添加_controller.forward1.0
在这里,您可以传递所需的值
如下图所示:
无效动画按钮{
如果_animation.value==0
_controller.forwardfrom:1.0;
其他的
_controller.reversefrom:1.0;
}
在代码中:
添加_controller.forward1.0
在这里,您可以传递所需的值
如下图所示:
无效动画按钮{
如果_animation.value==0
_controller.forwardfrom:1.0;
其他的
_controller.reversefrom:1.0;
}
据我所知,您希望使动画从1.0开始,而不是从0.0开始 我们到了 使全局变量如下:- 最后,您可以通过以下方式更改开始和结束动画值:-
据我所知,您希望使动画从1.0开始,而不是从0.0开始 我们到了 使全局变量如下:- 最后,您可以通过以下方式更改开始和结束动画值:-
如果要使用正向将反向驱动值的动画,即1.0→ 0.0,最简单的解决方案是使用:
如果要使用正向将反向驱动值的动画,即1.0→ 0.0,最简单的解决方案是使用:
你是说在美国?这难道不是一开始就让我不点击按钮就直接制作动画吗?我已经更新了我的答案。也许这就是你所需要的你在这个州是什么意思?这难道不是一开始就让我不点击按钮就直接制作动画吗?我已经更新了我的答案。也许这就是你需要的。你试过吗?\u controller.forwardfrom:1.0;?它将值设置为1.0并且不设置动画您是否尝试_controller.forwardfrom:1.0;?它将值设置为1.0,并且不设置动画
@override
void initState() {
super.initState();
controller=AnimationController(vsync: this, duration: Duration(seconds: 2));
animation = tween.animate(controller);
}
void accessToStartOfAnimation() {
print(tween.begin);
tween.begin = 1;
print(tween.begin);
}
@override
void initState() {
super.initState();
_animationController =
AnimationController(vsync: this, duration: Duration(milliseconds: 500));
_hideAnimation = ReverseAnimation(
CurvedAnimation(
parent: _animationController,
curve: Curves.fastOutSlowIn,
),
),
}