颤振,第二个动画控制器未设置动画,为什么?

时间:2020-02-16 12:21:58

标签: flutter dart flutter-animation

我有两个使用 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; 
...

我用两个不同的按钮调用了前进方法:

第一个和第二个相同:

RaisedButton(
    onPressed: () => {
       maanime.controller.forward()
       },

1 个答案:

答案 0 :(得分:1)

对不起,我的问题是animatedbuilder小部件,我不得不使用第二个控制器更改animation参数