如何使用Flutter悬停PopupmenuButton的颜色?

mlmc2os5  于 2022-12-14  发布在  Flutter
关注(0)|答案(1)|浏览(186)

我用Flutter构建了一个PopupMenuButton。我想在鼠标悬停时悬停按钮标题的文本,并且我想悬停PopupMenuButton项的背景。如果你们中有人知道如何解决这个问题,那就太好了。下面你可以找到我的代码。

PopupMenuButton(
                          tooltip: '',
                          color: Color(0xFF262533),
                          position: PopupMenuPosition.under,
                          child: Text(
                            'Agenturen & Clubs',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 24,
                              fontFamily: 'Poppins',
                            ),
                          ),
                          itemBuilder: (BuildContext context) =>
                              <PopupMenuEntry>[
                                const PopupMenuItem(
                                  child: ListTile(
                                    title: Text(
                                      'Escortagenturen',
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  ),
                                ),
                                const PopupMenuItem(
                                  child: ListTile(
                                    title: Text(
                                      'Bordelle',
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  ),
                                ),
                                const PopupMenuItem(
                                  child: ListTile(
                                    title: Text(
                                      'Laufhauser',
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  ),
                                ),
                                const PopupMenuItem(
                                  child: ListTile(
                                    title: Text(
                                      'Saunaclubs',
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  ),
                                ),
                                const PopupMenuItem(
                                  child: ListTile(
                                    title: Text(
                                      'Domina & BDSM-Studios',
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  ),
                                ),
                                const PopupMenuItem(
                                  child: ListTile(
                                    title: Text(
                                      'Tantra & Massaage-Studios',
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  ),
                                ),
                              ]),
vngu2lb8

vngu2lb81#

class OverlayAnimatedGridElement extends StatefulWidget {
            OverlayAnimatedGridElement(this.imagepath);
         final String imagepath;
          //  final String postTitle;
           //  final String postDetail;

  @override
  _OverlayAnimatedGridElementState createState() =>
      _OverlayAnimatedGridElementState();
}

class _OverlayAnimatedGridElementState extends State<OverlayAnimatedGridElement>
    with TickerProviderStateMixin {
  bool isHovered = false;

  @override
  void initState() {
    super.initState();
  }

  hoverActivation(hoverState) {
    setState(() {
      isHovered = hoverState;
    });
    print("activated" + hoverState.toString());
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        color: Colors.red,
        height: 200,
        width: 300,
        child: Stack(
          children: [
            Image.network(widget.imagepath),
            MouseRegion(
              onEnter: (event){
                hoverActivation(true);
              },
              onExit: (event){
                hoverActivation(false);
              },
              child: AnimatedContainer(
                duration: Duration(milliseconds: 200),
                color: Colors.black.withOpacity(isHovered ? 0.5 : 0),
              ),
            )
          ],
        ),
      ),
    );
  }
}

相关问题