Animation Class: Mixin
https://medium.com/flutter-community/dart-what-are-mixins-3a72344011f3
void main(){ runApp(new MaterialApp(home:new AnimationTest())); } class AnimationTest extends StatefulWidget { @override _AnimationTestState createState() => _AnimationTestState(); } class _AnimationTestState extends State<AnimationTest> with SingleTickerProviderStateMixin{ AnimationController animationController; @override void initState() { // TODO: implement initState super.initState(); animationController = new AnimationController( vsync: this, duration: new Duration(seconds: 5), ); animationController.addListener((){ this.setState((){}); }); } @override Widget build(BuildContext context) { return new GestureDetector( child: new Container( color:Colors.white, child: new Center( child: new Text( animationController.isAnimating? animationController.value.toStringAsFixed(3): "Press to start!", style: TextStyle(color:Colors.black, decoration: TextDecoration.underline, decorationColor: Colors.black, ), ), ), ), onTap: (){ animationController.forward(from: 0.0); }, ); } @override void dispose(){ animationController.dispose(); super.dispose(); } }
Comments
Post a Comment