1

I build this code below that makes possible to show my Popupmenubuttons Items when I put the cursor over the button without clicking the button. But there is a problem. I can show my items with this method but I can not make possible to close my items in the moment I move my cursor from the button. Please look carefully my code and tell me if you have any idea how to solve this.

openPopUpItem() {
    GestureDetector? detector;
    searchForGestureDetector(BuildContext element) {
      element.visitChildElements((element) {
        if (element.widget != null && element.widget is GestureDetector) {
          detector = element.widget as GestureDetector;
        } else {
          searchForGestureDetector(element);
        }
      });
    }

    searchForGestureDetector(keyList[0].currentContext!);
    detector!.onTap!();
  }

 InkWell(
                  onHover: (value) {
                    if (value) openPopUpItem2();
                  },
                  onTap: () {},
                  child: PopupMenuButton(
                      key: keyList[2],
                      tooltip: '',
                      color: Color(0xFF262533),
                      position: PopupMenuPosition.under,
                      child: MouseRegion(
                        onEnter: (details) =>
                            setState(() => ishovering2 = true),
                        onExit: (details) => setState(() {
                          ishovering2 = false;
                        }),
                        child: Text(
                          'Blog',
                          style: TextStyle(
                            color: ishovering2 ? Colors.pink : Colors.white,
                            fontSize: 24,
                            fontFamily: 'Poppins',
                          ),
                        ),
                      ),
                      itemBuilder: (BuildContext context) => <PopupMenuEntry>[
                            PopupMenuItem(
                              child: OnHover(
                                builder: (isHovered) {
                                  final color = isHovered
                                      ? Colors.pink
                                      : const Color(0xFF262533);
                                  return ListTile(
                                    title: const Text(
                                      'Archiv',
                                      style: TextStyle(color: Colors.white),
                                    ),
                                    enabled: true,
                                    hoverColor: color,
                                    onTap: () {},
                                  );
                                },
                              ),
                            ),
                          ]),
                ),

1 Answers1

1

use MouseRegion-class

https://api.flutter.dev/flutter/widgets/MouseRegion-class.html

   MouseRegion(
          onEnter: _showpopupmenu,
          onHover: (){},
          onExit: _removepopupmenu,
          child: Container(
            color: Colors.lightBlueAccent,
    
          ),
        ),
MANISH DAYMA
  • 1,126
  • 3
  • 18