|
| 1 | +/// |
| 2 | +/// Created by NieBin on 2019年6月9日 |
| 3 | +/// Github: https://github.com/nb312 |
| 4 | +/// Email: niebin312@gmail.com |
| 5 | +/// |
| 6 | +import 'package:flutter/material.dart'; |
| 7 | +import 'package:flutter_widgets/const/_const.dart'; |
| 8 | +import 'dart:math'; |
| 9 | + |
| 10 | +class RotationPage extends StatefulWidget { |
| 11 | + @override |
| 12 | + _RotationState createState() => _RotationState(); |
| 13 | +} |
| 14 | + |
| 15 | +class _RotationState extends State<RotationPage> |
| 16 | + with SingleTickerProviderStateMixin { |
| 17 | + AnimationController _controller; |
| 18 | + Animation<double> _rotationAnim; |
| 19 | + Animation<Offset> _offsetAnim; |
| 20 | + Animation<Decoration> _decorationAnim; |
| 21 | + |
| 22 | + Widget _rotation() => RotationTransition( |
| 23 | + turns: _rotationAnim, |
| 24 | + alignment: Alignment.center, |
| 25 | + child: Text( |
| 26 | + "This is my first rotation transition.", |
| 27 | + style: TextStyle(color: BLUE_DEEP, fontSize: 10), |
| 28 | + ), |
| 29 | + ); |
| 30 | + |
| 31 | + Widget _scale() => ScaleTransition( |
| 32 | + scale: _rotationAnim, |
| 33 | + child: Text("Scale transition."), |
| 34 | + ); |
| 35 | + |
| 36 | + Widget _slide() => SlideTransition( |
| 37 | + position: _offsetAnim, |
| 38 | + child: Text( |
| 39 | + "Offset", |
| 40 | + style: TextStyle(color: PURPLE), |
| 41 | + ), |
| 42 | + ); |
| 43 | + |
| 44 | + Widget _sizeTrans() => SizeTransition( |
| 45 | + sizeFactor: _rotationAnim, |
| 46 | + child: Container( |
| 47 | + width: 100, |
| 48 | + height: 100, |
| 49 | + color: RED_LIGHT, |
| 50 | + ), |
| 51 | + ); |
| 52 | + |
| 53 | + Widget _decoratedTrans() => DecoratedBoxTransition( |
| 54 | + decoration: _decorationAnim, |
| 55 | + child: Container( |
| 56 | + constraints: BoxConstraints.expand(height: 100, width: 200), |
| 57 | + child: InkWell( |
| 58 | + child: Center( |
| 59 | + child: Text("Click Me"), |
| 60 | + ), |
| 61 | + onTap: () { |
| 62 | + _controller.reset(); |
| 63 | + _controller.forward(); |
| 64 | + }, |
| 65 | + ), |
| 66 | + )); |
| 67 | + |
| 68 | + @override |
| 69 | + void initState() { |
| 70 | + _controller = AnimationController( |
| 71 | + vsync: this, |
| 72 | + duration: Duration(seconds: 3), |
| 73 | + ); |
| 74 | + CurvedAnimation _curve = |
| 75 | + CurvedAnimation(parent: _controller, curve: Curves.elasticIn); |
| 76 | + _rotationAnim = Tween(begin: 0.0, end: pi).animate(_curve); |
| 77 | + _offsetAnim = |
| 78 | + Tween(begin: Offset(0.0, 0.0), end: Offset(5.0, 1.0)).animate(_curve); |
| 79 | + _decorationAnim = DecorationTween( |
| 80 | + begin: ShapeDecoration( |
| 81 | + shape: StadiumBorder( |
| 82 | + side: BorderSide(color: RED_LIGHT, width: 1))), |
| 83 | + end: ShapeDecoration( |
| 84 | + shape: CircleBorder(side: BorderSide(color: BLUE, width: 4)))) |
| 85 | + .animate(_curve); |
| 86 | + super.initState(); |
| 87 | + } |
| 88 | + |
| 89 | + @override |
| 90 | + Widget build(BuildContext context) { |
| 91 | + return Scaffold( |
| 92 | + appBar: AppBar( |
| 93 | + title: Text(PageName.ANIM_ROTATION), |
| 94 | + ), |
| 95 | + body: Column( |
| 96 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 97 | + mainAxisAlignment: MainAxisAlignment.center, |
| 98 | + children: <Widget>[ |
| 99 | + _rotation(), |
| 100 | + _scale(), |
| 101 | + _slide(), |
| 102 | + _sizeTrans(), |
| 103 | + _decoratedTrans(), |
| 104 | + ], |
| 105 | + ), |
| 106 | + ); |
| 107 | + } |
| 108 | +} |
0 commit comments