How can I make the a RotateTransition rotate my widget half way (180 degrees)

Viewed 45

How can I make a widget rotate to a particular degree using RoatateTransition: My code looks like this:

AnimationController _animationController;
  
  @override
  void initState() {
    super.initState();
    _animationController = AnimationController(vsync: this, duration: Duration(seconds: 1));
    _animationController.repeat();
  }

  RotationTransition(
    turns: this.animationController,
    child: Icon(Icons.arrow_drop_down_sharp, color: Colors.white, size: 25,)
 )

but my issue is that the code continuously rotates, would love to make it rotate to a particular degree and reverse back.

1 Answers

You need to defined like

 AnimationController  _animationController = AnimationController(
          duration: const Duration(seconds: 1),
          vsync: this,
          value: 0,
          lowerBound: 0,
          upperBound: 0.5
      );
 Animation<double>  _animation = CurvedAnimation(parent: _controller, curve: Curves.linear);

and

 RotationTransition(
    turns: _animation,
    child: Icon(Icons.arrow_drop_down_sharp, color: Colors.white, size: 25,)
 )
Related