1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| class _MyHomePageState extends State<MyHomePage> with SingleTickerProvider特性StateMixin //具备TickerProvider特性
//定义动画初始值 AnimationController _controller; double _size = 100;
//动画监听 @override void initState() { super.initState(); _controller = AnimationController( vsync: this, duration: Duration(milliseconds: 500), lowerBound: 100, upperBound: 200) ..addStatusListener((AnimationStatus status) { if(status == AnimationStatus.completed){ _controller.reverse(); }else if(status == AnimationStatus.dismissed){ _controller.forward(); } }) ..addListener(() { setState(() { _size = _controller.value; }); }); } //body Center( child: GestureDetector( onTap: (){_controller.forward();}, child: Container( height: _size, width: _size, color: Colors.blue, alignment: Alignment.center, child: Text("点我,开始动画"), ), ), ) //释放资源 @override void dispose() { super.dispose(); _controller.dispose(); }
|