Flutter:AnimationController-没有按钮来控制它吗?

问题描述 投票:0回答:1

我用AnimationController制作了一个动画,并且我希望它在用户打开应用程序时开始播放,并且当动画结束时,用户无需按任何按钮即可转到另一页。

flutter dart flutter-animation
1个回答
1
投票

StatefulWidget子类中使用此代码。

AnimationController _controller; // member variable

@override
void initState() {
  super.initState();

  _controller = AnimationController(vsync: this, duration: Duration(seconds: 1));

  // start the animation when this page opens
  _controller.forward().then((value) {
    // animation is finished, you can now go to any page
    Navigator.pushNamed(context, "/secondPage");
  });

  _controller.addListener(() { 
    // this is your listener, you can also control lots of things from here
  });
}
© www.soinside.com 2019 - 2024. All rights reserved.