I want mouseover to act like Twitter’s unfollow button:
If I follow someone on Twitter, I hover over the button with the text "Follow" and the color of the button changes to red with the text "Unfollow". How can I achieve this?
I googled but couldn’t find any results.
My code:
GestureDetector(
onTap: () => setState(() => following = !following),
child: Container(
padding: const EdgeInsets.all(10.0),
decoration: following ? BoxDecoration(border: Border.all(color: Colors.cyan), borderRadius: BorderRadius.circular(25.0)) : BoxDecoration(color: Colors.cyan, borderRadius: BorderRadius.circular(25.0)),
child: Row(
children: [
Icon(following ? Icons.favorite : Icons.person_add_alt, color: following ? Colors.cyan : Colors.white),
const SizedBox(width: AppSizes.10.0),
Text(
following ? "Following" : "Follow",
style: TextStyle(color: following ? Colors.cyan : Colors.white),
),
],
),
),
),
Feel free to leave a comment if you need more information.
How to make mouseover act like Twitter’s unfollow button? I would appreciate any help. Thank you in advance!
2
Answers
Wrap your
GestureDetector
withMouseRegion
to get mouse event.Short Answer
use Mouse Region Widget like below and Track mouse events
Long Answer
I made a sample code for you. you can easily track mouse and make what you want with
AnimatedContainer
orAnimatedSwitcher
.here is the result