【发布时间】:2020-02-16 12:21:58
【问题描述】:
我有两个使用 TickerProviderStateMixin 的动画控制器,第一个动画运行顺利,而第二个动画在我触发 forward 方法时没有动画:这是它们的声明:
class HomeAnimator extends StatefulWidget {
@override
_HomeAnimatorState createState() => _HomeAnimatorState();
}
class _HomeAnimatorState extends State<HomeAnimator>
with TickerProviderStateMixin {
AnimationController _controller;
AnimationController _signupctrl;
@override
void initState() {
super.initState();
_controller =
AnimationController(duration: Duration(milliseconds: 900), vsync: this);
_signupctrl =
AnimationController(duration: Duration(milliseconds: 900), vsync: this);
// _controller.forward();
}
@override
void dispose() {
super.dispose();
_controller.dispose();
_signupctrl.dispose();
}
@override
Widget build(BuildContext context) {
return Dahome(controllers: [_controller,_signupctrl]);
}
}
我有两个用于不同动画集的文件:
-- Mahome_EnterAnimation:点击登录按钮时 这是一篇相关的文章:
class EntAnime {
EntAnime(this.controller)
: opanime = Tween<double>(begin: 1, end: 0).animate(CurvedAnimation(
parent: controller,
curve: Interval(0, 0.5, curve: Curves.fastOutSlowIn),
)),
r_opanime = Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
parent: controller,
curve: Interval(0, 0.5, curve: Curves.fastOutSlowIn),
)),
hfact = Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
parent: controller,
curve: Interval(0, 0.5, curve: Curves.fastOutSlowIn),
)),
-- Mahome_SignupAnime:当我按下注册按钮时
class SignupAnime {
SignupAnime(this.controller):
qopanime = Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
parent: controller,
curve: Interval(0.0, 0.5, curve: Curves.fastOutSlowIn),
)),
qhfact = Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
parent: controller,
curve: Interval(0.5, 0.9, curve: Curves.fastOutSlowIn),
));
final AnimationController controller;
final Animation<double> qopanime;
final Animation<double> qhfact;
}
这就是我声明它的方式:
class Dahome extends StatefulWidget {
Dahome({Key key, this.title, @required List<AnimationController> controllers})
: daanime = EntAnime(controllers[0]),
signanime = SignupAnime(controllers[1]),
super(key: key);
final EntAnime daanime;
final SignupAnime signanime;
final String title;
Dastate createState() => Dastate(daanime, signanime);
// @override
}
class Dastate extends State<Dahome> {
Dastate(this.maanime, this.loganime);
final EntAnime maanime;
final SignupAnime loganime;
...
我在两个不同的按钮中调用了 forward 方法:
这里是第一个,第二个也是这样:
RaisedButton(
onPressed: () => {
maanime.controller.forward()
},
【问题讨论】:
-
您的代码中没有调用
forward()方法,您如何创建EntAnime和SignupAnime对象? -
loganime.controller.forward()在哪里? -
我也是这样写的,顺便感谢表弟借我一些时间。
-
不要使用这个:
Dastate(this.maanime, this.loganime)而是从Dastate中删除final EntAnime maanime; final SignupAnime loganime;字段和构造函数,并从widget.daanime和widget.signanime中使用widget.signanime类 -
刚刚完成,当我按下按钮时,第二个控制器(动画集)仍然没有动画,但当我在颤振控制台中点击 r 时,它直接进入最终值没有动画。 (不过很好的提示,代码现在更漂亮了)
标签: flutter dart flutter-animation