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

前端 未结 8 1470
走了就别回头了
走了就别回头了 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:03

    From Flutter beta version 1.19.0-4.1.pre, add id to body and set cursor of that doesn't work. Because flt-glass-pane is replacing the cursor. So the solution is that set cursor directly to flt-glass-pane.

    Below is the update that is working.

    class HandCursor extends MouseRegion {
        static final appContainer = html.window.document.querySelectorAll('flt-glass-pane')[0];
        HandCursor({Widget child}) : super(
            onHover: (PointerHoverEvent evt) {
                appContainer.style.cursor='pointer';
            },
            onExit: (PointerExitEvent evt) {
                appContainer.style.cursor='default';
            },
            child: child
        );    
    }
    

提交回复
热议问题