Has*_*sen 1 animation dart flutter
我想传入一个值来将起始动画值设置为 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();
},
);
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用:
_controller.forward(from: 0.0);
Run Code Online (Sandbox Code Playgroud)
或者
_controller.reverse(from: 1.0);
Run Code Online (Sandbox Code Playgroud)
并设置您需要的值
或者为了设置初始值,您可以使用
_controller.value = widget.start;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3659 次 |
| 最近记录: |