AnimatedRotation for animating compass
I am trying to add a compass to my app. What is the best way to animate the rotation from 359 to 0 or 0 to 359? Is there a better suited widget for this type of rotation?
AnimatedRotation(
duration: const Duration(milliseconds: 250),
turns: -heading / 360.0,
curve: Curves.linear,
Tried to do it by adding the difference instead of assigning the angle but it can overflow if it is rotating on same direction.
if(previousHeading - heading > 180) {
turns += ((360.0 - previousHeading) + heading) / 360.0;
}
else if(previousHeading - heading < -180) {
turns -= ((360.0 - heading + previousHeading)) / 360.0;
}
else {
turns += ((previousHeading - heading) / 360.0);
}
previousHeading = heading;