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 48 49 50 51 52
| class GMExampleAlignTransitionTest extends StatefulWidget { GMExampleAlignTransitionTest({Key key}) : super(key: key);
@override _GMExampleAlignTransitionTestState createState() => _GMExampleAlignTransitionTestState(); }
class _GMExampleAlignTransitionTestState extends State<GMExampleAlignTransitionTest> with SingleTickerProviderStateMixin { AnimationController _animationController;
Animation<AlignmentGeometry> _animation;
@override void initState() { this._animationController = AnimationController(duration: Duration(seconds: 2), vsync: this); this._animation = Tween<AlignmentGeometry>( begin: Alignment.topLeft, end: Alignment.bottomRight) .animate(this._animationController);
//开始动画 this._animationController.forward();
super.initState(); }
@override void dispose() { this._animationController.dispose(); super.dispose(); }
@override Widget build(BuildContext context) { return Container( height: 200, width: 200, color: Colors.blue, child: AlignTransition( alignment: _animation, child: Container( height: 30, width: 30, color: Colors.red, ), ), ); } }
|