Flutter-Web: Mouse hover -> Change cursor to pointer

前端 未结 8 1474
走了就别回头了
走了就别回头了 2021-02-05 06:59

How can the cursor appearance be changed within Flutter? I know that with the Listener() Widget we can listen for Mouse-Events, but I haven\'t found any information regarding h

相关标签:
8条回答
  • 2021-02-05 07:23
    final appContainer 
         = html.document.getElementsByTagName('body')[0] as html.Element;
    
                GestureDetector(
                            child: MouseRegion(
                              child: Text(
                                'https://github.com/yumi0629',
                                style: textStyle,
                              ),
                              onHover: (_) => appContainer.style.cursor = 'pointer',
                              onExit: (_) => appContainer.style.cursor = 'default',
                            ),
                            onTap: () {
                              print('open');
                              js.context.callMethod(
                                  'open', ['https://github.com/yumi0629']);
                            },
                          )
    
    0 讨论(0)
  • 2021-02-05 07:25

    You can use an InkWell that has an onHover event

    InkWell(
        onTap: () {},
        onHover: (value) {
          setState(() {
            isHovered = value;
          });
        },
        child: Container(
          width: 50,
          height: 72,
          color: Colors.black   
        )
    );
    

    Make sure to have something onTap, even an empty function, else it is considered to be disabled, and the hover won't work

    0 讨论(0)
提交回复
热议问题