title: Rotate icon 180 degree with animation in flutter
body: <p>I have a <code>IconButton</code>, Normally, It's icon is <code>Icons.expand_more</code> but When I press that its icon should be <code>Icons.expand_less</code>. I want to animated this so that if I press that button, it will rotate and point the downwords from upwords. and same when I press the <code>expand_less</code> then it should become <code>expand_more</code> with rotating animation. How can I acheive this ?
  below is my code :</p>
  <pre><code>    IconButton(
        icon:  _expanded ? Icon(Icons.expand_less) : Icon(Icons.expand_more),
        onPressed: () {
          setState(() {
             _expanded = !_expanded;
          });
        },
     )
  </code></pre>
  <p>I tried to use animatedContainer but it didn't work as I am using two different icons and that rotation effect I cannot acheive with this.
  I also tried to rotate the icon with below approach but it cannot show the animation when it is rotating from 0 to 180 degree.</p>
  <pre><code>IconButton(
                icon: AnimatedContainer(
                    duration: Duration(seconds: 3),
                    child: Transform.rotate(
                        angle: _expanded ? 0 : 180 * math.pi / 180,
                        child: Icon(Icons.expand_less))),
                // icon:
                //     _expanded ? Icon(Icons.expand_less) : Icon(Icons.expand_more),
                onPressed: () {
                  setState(() {
                    _expanded = !_expanded;
                  });
                },
              )
  </code></pre>
  <p>This is before expansion :</p>
  <blockquote>
  <p><a href="https://i.stack.imgur.com/xR3EO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xR3EO.png" alt="before expansion" /></a></p>
  </blockquote>
  <p>This is after expansion :</p>
  <blockquote>
  <p><a href="https://i.stack.imgur.com/G0cKK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/G0cKK.png" alt="after expansion" /></a></p>
  </blockquote>
  <p><em>I want the rotation animation on button click.</em></p>