Home > database >  How do i make my Inkwell onhover work on my menu items?
How do i make my Inkwell onhover work on my menu items?

Time:05-23

I am trying to create an onHover effect on my navigation menu, my approach was to create boolean list as long as my navigation menu items and with initial false values, then when a menu item is hovered change the color, my problem is the value parameter from the inkwell onhover function is printing out the right value to console but it's not affecting my menu item color, any suggestions? When i run it, it remains the color red with the onhover having no effect

 final List hover = [false, false, false, false, false];

       InkWell(
                    onHover: (value) {
                      setState(() {
                        value ? hover[1] = true : hover[1] = false;
                      });
                    },
                    onTap: () {},
                    child: Text('Org Chart',
                        style: TextStyle(
                            color: hover[1] ? Colors.black : Colors.red))),

CodePudding user response:

Are you sure you don't have the hover variable inside build method? Make sure it is correct state variable of StatefulWidget. I would also recommend removing the final annotation since you want to change it on hover. Also you can simplify your code like this:

setState(() {
  hover[1] = value;
});
  • Related