AnimatedWidget Example

This Article is posted by seven.srikanth at 8/23/2020 8:37:35 AM

Here is an example of AnimatedWidget in flutter. _MyAnimatedContainerState(contoller); } class _MyAnimatedContainerState extends State { int counter = 0; final AnimationController _controller; _MyAnimatedContainerState(this._controller); @override Widget build(BuildContext context) { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( padding: const EdgeInsets.all(48.0), child: MyAnimatedWidget( controller: _controller, counter: counter, ), ), RaisedButton( onPressed: () { setState(() { counter++; }); }, child: Text('Click here '), ), ], ); } } class MyAnimatedWidget extends AnimatedWidget { final AnimationController controller; final int counter; const MyAnimatedWidget({Key key, this.controller, this.counter}) : super(key: key, listenable: controller); @override Widget build(BuildContext context) { return Transform.rotate( angle: controller.value * 2.0 * math.pi, child: Container( child: Text( 'Clicked $counter times', ), ), ); } } class MyAnimatedContoller extends StatefulWidget { @override _MyAnimatedContollerState createState() => _MyAnimatedContollerState(); } class _MyAnimatedContollerState extends State with SingleTickerProviderStateMixin { AnimationController _controller; @override void initState() { super.initState(); _controller = AnimationController(duration: Duration(seconds: 1), vsync: this) ..repeat(); } @override void dispose() { super.dispose(); _controller.dispose(); } @override Widget build(BuildContext context) { return MyAnimatedContainer(contoller: _controller); } } `

Tags:



0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.




© 2018 - Fluttercentral | Email to me - Seven.srikanth@gmail.com