gpt4 book ai didi

animation - Flutter 设置开始动画值

转载 作者:IT王子 更新时间:2023-10-29 07:10:51 25 4
gpt4 key购买 nike

我想传入一个值来设置起始动画值为1.0,而不是从0开始,但我不知道这是如何实现的。

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.reverse(from: 1.0);

然后设置你需要的值

或者你可以使用设置初始值

_controller.value = widget.start;

关于animation - Flutter 设置开始动画值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57197922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com