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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| import 'package:flutter/material.dart';
void main() => runApp(new AnimationApp());
class AnimationApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: 'Animation', theme: new ThemeData(primarySwatch: Colors.blue), home: new HomePage( title: '动画示例', ), ); } }
class HomePage extends StatefulWidget { final String title;
HomePage({Key key, this.title}) : super(key: key);
@override State<StatefulWidget> createState() => new _HomePageState(); }
class _HomePageState extends State<HomePage> with TickerProviderStateMixin { AnimationController controller; CurvedAnimation curveEaseIn, bounceIn, linear, decelerate; bool _animationFlag = true;
@override void initState() { super.initState(); controller = new AnimationController( duration: new Duration(milliseconds: 2000), vsync: this); curveEaseIn = new CurvedAnimation(parent: controller, curve: Curves.easeIn); bounceIn = new CurvedAnimation(parent: controller, curve: Curves.bounceIn); linear = new CurvedAnimation(parent: controller, curve: Curves.linear); decelerate = new CurvedAnimation(parent: controller, curve: Curves.decelerate); }
@override Widget build(BuildContext context) { buildItemWidget( CurvedAnimation animation, MaterialColor color, String itemText) { return new Column( children: <Widget>[ new FadeTransition( opacity: animation, child: new FlutterLogo( size: 100.0, colors: color, ), ), new Text(itemText) ], ); }
return new Scaffold( appBar: new AppBar( title: new Text(widget.title), ), floatingActionButton: new FloatingActionButton( onPressed: () { if (_animationFlag) { controller.forward(); } else { controller.reverse(); } _animationFlag = !_animationFlag; }, child: new Icon(Icons.star), ), body: new Center( child: new GridView.extent( maxCrossAxisExtent: 170.0, padding: const EdgeInsets.all(12.0), children: <Widget>[ buildItemWidget(curveEaseIn, Colors.blue, 'Curves.easeIn'), buildItemWidget(bounceIn, Colors.amber, 'Curves.bounceIn'), buildItemWidget(linear, Colors.red, 'Curves.linear'), buildItemWidget(decelerate, Colors.indigo, 'Curves.decelerate'), buildItemWidget( new CurvedAnimation( parent: controller, curve: Curves.elasticIn), Colors.pink, 'Curves.elasticIn'), buildItemWidget( new CurvedAnimation(parent: controller, curve: Curves.ease), Colors.purple, 'Curves.ease'), ], ), ), ); } }
DART
|