Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从dart 2中调用作为参数传递的javascript函数_Dart_Dart Js Interop - Fatal编程技术网

从dart 2中调用作为参数传递的javascript函数

从dart 2中调用作为参数传递的javascript函数,dart,dart-js-interop,Dart,Dart Js Interop,我们如何在dart 2中实现这一点 content_script.js: chrome.runtime.sendMessage(“hello”),函数(响应){ 控制台日志(响应); }); background.js: chrome.runtime.onMessage.addListener(函数(a、b、responseCallback){ responseCallback(“世界”); }); 当响应回调(“世界”)从dart调用,但不会将响应发送回发件人 我已经实现了一个示例,该示例

我们如何在dart 2中实现这一点

content_script.js:

chrome.runtime.sendMessage(“hello”),函数(响应){ 控制台日志(响应); });

background.js:

chrome.runtime.onMessage.addListener(函数(a、b、responseCallback){
responseCallback(“世界”);
});

响应回调(“世界”)从dart调用,但不会将响应发送回发件人

我已经实现了一个示例,该示例能够在触发事件时从事件中读取参数,但无法发送响应,因为
responseCallback
作为参数传递:

API文档:


经过一段时间的磕磕绊绊之后,我在stackoverflow上发现了关于
chrome.runtime.onMessage
的以下内容:

chrome.runtime.onMessage.addListener

当事件侦听器返回时,此函数将无效,除非您从事件侦听器返回true以指示您希望异步发送响应(这将保持消息通道向另一端开放,直到调用sendResponse)

那些对使用dart js interop实现事件侦听器(“类似于上述”)感兴趣的人可以查看以下repo: