Flutter的Animation中TweenSequence的用法

class _MyHomePageState2 extends State with SingleTickerProviderStateMixin {
  AnimationController _controller;
  Animation _animation;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
        vsync: this, duration: Duration(milliseconds: 3000));
    _controller.addListener(() {
      setState(() {});
    });
    _animation = TweenSequence([//这是一个动画序列,weight表示权重
      TweenSequenceItem(tween: Tween(begin: 50.0,end: 100.0).chain(CurveTween(curve: Curves.easeOut)),weight: 50),
      TweenSequenceItem(tween: Tween(begin: 100.0,end: 150.0).chain(CurveTween(curve: Curves.easeOut)),weight: 50)
    ]).animate(_controller);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Center(
          child: InkWell(
            onTap: () {
              if (_controller.isDismissed) {
                _controller.forward();
              } else {
                _controller.reverse();
              }
            },
            child: Container(
              width: _animation.value,
              height: _animation.value,
              decoration: BoxDecoration(
                  shape: BoxShape.circle, color: Colors.blue),
            ),
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容