Flutter 鼠标右键

import 'package:universal_html/html.dart';


void main() {

​	// Disable the default browser behavior for right clicking 
    // 屏蔽浏览器默认的右键点击事件
 	window.document.onContextMenu.listen((evt) => evt.preventDefault());

​	runApp(MyApp());
}

//具体使用
Container(
child:Listener(
            onPointerDown: _onPointerDown,
            child: Container(
              decoration: BoxDecoration(
                  border: Border.all(color: editWidgetItem == element ? 
              Colors.blueAccent : Colors.transparent)),
              padding: const EdgeInsets.all(2),
              child: buildDetailsWidget(element),
            ),
          ),
),


  /// Callback when mouse clicked on `Listener` wrapped widget.
  Future _onPointerDown(PointerDownEvent event) async {
    // Check if right mouse button clicked
    if (event.kind == PointerDeviceKind.mouse && event.buttons == kSecondaryMouseButton) {
      final overlay = Overlay.of(context).context.findRenderObject() as RenderBox;
      final menuItem = await showMenu(
          context: context,
          items: [
            PopupMenuItem(child: Text('Copy'), value: 1),
            PopupMenuItem(child: Text('Cut'), value: 2),
          ],
          position: RelativeRect.fromSize(event.position & Size(48.0, 48.0), overlay.size));
      // Check if menu item clicked
      switch (menuItem) {
        case 1:
          ScaffoldMessenger.of(context).showSnackBar(SnackBar(
            content: Text('Copy clicket'),
            behavior: SnackBarBehavior.floating,
          ));
          break;
        case 2:
          ScaffoldMessenger.of(context)
              .showSnackBar(SnackBar(content: Text('Cut clicked'), behavior: SnackBarBehavior.floating));
          break;
        default:
      }
    }
  }

你可能感兴趣的:(flutter)