0

I have a button with a icon inside of it. Right now I am using two different icons and change them onTap:

Widget build(BuildContext context) {
return GestureDetector(
  onTap: () {
    setState(() {
        _isDropdownOpened = !_isDropdownOpened;
      }
  ...
  },
  child: 
        _isDropdownOpened
            ? SvgPicture.asset(
                'images/icons/arrow_down_primary.svg',
                width: scaleWidth(12),
              )
            : SvgPicture.asset(
                'images/icons/arrow_up_primary.svg',
                width: scaleWidth(12),
              ),
  ),
);

This is working but I would like to have a RotationTransition. How can I rotate my icon onTap with animation, so I don't need two different SVGs?

Chris
  • 1,828
  • 6
  • 40
  • 108

1 Answers1

2

use RotatedBox widget and change its rotation in your setState

you can do like this

 child: RotatedBox(
  quarterTurns: _isDropdownOpened? 2:0,
  child: SvgPicture.asset(
            'images/icons/arrow_down_primary.svg',
            width: scaleWidth(12),
          ),
) 

if you want to apply animation to the rotation as well consider looking to this

Moaid ALRazhy
  • 1,604
  • 1
  • 3
  • 13