我想传递一个值来将动画的起始值设置为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();
},
);
}
}
答案 0 :(得分:2)
您可以使用:
a0acb90300000000
Lets add some spaces and capitalize letters:
A0 AC B9 03 00 00 00 00
62500000
Windows calculator converts to:
3B9ACA0
This is a number from a calculator, lets add spaces right to left
3 B9 AC A0
Lets add some zeros to the left side, we have:
00 00 00 00 03 B9 AC A0
Before:
A0 AC B9 03 00 00 00 00
或
_controller.forward(from: 0.0);
并设置所需的值
或者您可以使用设置初始值
_controller.reverse(from: 1.0);
答案 1 :(得分:0)
在您的代码内:
添加_controller.forward(1.0);
。
您可以在此处传递所需的值。
像下面这样:
void animateButton() {
if (_animation.value == 0)
_controller.forward(from: 1.0);
else
_controller.reverse(from: 1.0);
}
答案 2 :(得分:0)
据我了解,您要使动画从1.0开始而不是从0.0开始 所以这里是..
设置全局变量,例如:-
<div>
<label>Wafer Type:</label>
<select name="s1">
<option value="1"> First </option>
<option value="2"> Second </option>
</select>
</div>
<input type="text" name="lotNo" />
覆盖initState方法:-
Animation<double> animation;
AnimationController controller;
Tween<double> tween = Tween(begin: 0, end: 100);
最后,您可以通过以下方法更改开始和结束动画值:-
@override
void initState() {
super.initState();
controller=AnimationController(vsync: this, duration: Duration(seconds: 2));
animation = tween.animate(controller);
}
答案 3 :(得分:0)
如果您想使用forward()
将反向驱动值的动画,即1.0 → 0.0
,最简单的解决方案是使用ReverseAnimation:
@override
void initState() {
super.initState();
_animationController =
AnimationController(vsync: this, duration: Duration(milliseconds: 500));
_hideAnimation = ReverseAnimation(
CurvedAnimation(
parent: _animationController,
curve: Curves.fastOutSlowIn,
),
),
}