Flutter rotate animation, tutorial and example.

Flutter Developer
2 min readSep 14, 2021

--

First, let your widget state class implement SingleTickerProviderStateMixin.

Secondly, define an AnimationController and don't forget to dispose it. If you are not yet using null-safe, remove the late keyword.

late AnimationController _controller;@override
void initState() {
_controller = AnimationController(
duration: const Duration(milliseconds: 5000),
vsync: this,
);
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}

Then wrap your Widget with RotationTransition.

RotationTransition(
turns: Tween(begin: 0.0, end: 1.0).animate(_controller),
child: Icon(Icons.stars),
),

Finally, call methods on the AnimationController to start/stop animation.

  • Run the animation once, use .forward
  • Loop the animation, use .repeat
  • Stop immediately, use .stop
  • Stop and set it back to original rotation, use .reset
  • Stop and animate to a rotation value, use .animateTo

--

--

Flutter Developer
Flutter Developer

Written by Flutter Developer

Flutter and Native Android developer

No responses yet