0

我已向 IFrameElement 添加了一个 EventListener,但它从未被调用过。

监听器定义:

  EventListener eventListener = (e) {
    print("Lisenter clicked.");
  };

IFrameElement 定义:

  var type = 'click';

  IFrameElement element = IFrameElement()
    ..width = (MediaQuery.of(context).size.width - 400).toString()
    ..height = MediaQuery.of(context).size.height.toString()
    ..srcdoc = value
    ..addEventListener(type, eventListener)
    ..style.border = 'none';

  ui.platformViewRegistry.registerViewFactory(
      createdViewId,
          (int viewId) => element);

调度事件定义:

marker.addListener('click', function() {dispatchEvent(new Event("click"));console.log("woot");});

单击标记时在控制台中找到“woot”,但我从未看到“单击侦听器”。我究竟做错了什么?

在此处输入图像描述

4

1 回答 1

0

我最终得到以下结果:

    "marker.addListener('click', function() {dispatchEvent(new MouseEvent('click', {view: window, bubbles: true, cancelable: true }));"
        "var o = Object.create(null);"
        "o.id = \"${property.id}\";"
        ""
        "console.log(o);"
        "window.parent.postMessage(o);"
        ""
        "});\n";

然后我在窗口上附加一个监听器:

window.onMessage.listen((onData) {
  // do things
  if (messageEvent.data["id"] == property.id) { }
})
于 2020-01-22T02:12:45.007 回答