<p>Here is an example of AnimatedWidget in flutter.</p> <pre> _MyAnimatedContainerState(contoller); </pre> <p>}</p> <p>class _MyAnimatedContainerState extends State { int counter = 0; final AnimationController _controller;</p> <p>_MyAnimatedContainerState(this._controller);</p> <p>@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 '), ), ], ); } }</p> <p>class MyAnimatedWidget extends AnimatedWidget { final AnimationController controller; final int counter;</p> <p>const MyAnimatedWidget({Key key, this.controller, this.counter}) : super(key: key, listenable: controller);</p> <p>@override Widget build(BuildContext context) { return Transform.rotate( angle: controller.value * 2.0 * math.pi, child: Container( child: Text( 'Clicked $counter times', ), ), ); } }</p> <p>class MyAnimatedContoller extends StatefulWidget { @override _MyAnimatedContollerState createState() => _MyAnimatedContollerState(); }</p> <p>class _MyAnimatedContollerState extends State with SingleTickerProviderStateMixin { AnimationController _controller;</p> <p>@override void initState() { super.initState(); _controller = AnimationController(duration: Duration(seconds: 1), vsync: this) ..repeat(); }</p> <p>@override void dispose() { super.dispose(); _controller.dispose(); }</p> <p>@override Widget build(BuildContext context) { return MyAnimatedContainer(contoller: _controller); } } `</p>
AnimatedWidget Example
This Article is posted by seven.srikanth at 8/23/2020 8:37:35 AM
Check out our other latest articles
Safearea widget - How to avoid visual overlap with Notch on flutter mobile app?How to convert row of widgets into column of widgets in flutter based on screen size?
How to run Flutter programs from GitHub?
How to get screen orientation in flutter?
NavigationRail example in flutter
Tags:
Check out our other latest articles
Safearea widget - How to avoid visual overlap with Notch on flutter mobile app?How to convert row of widgets into column of widgets in flutter based on screen size?
How to run Flutter programs from GitHub?
How to get screen orientation in flutter?
NavigationRail example in flutter