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();
  }
}

你可能感兴趣的:(Flutter的Animation中TweenSequence的用法)