Dart SDK 0.8.10.3_r29803 dart:js callbacks

孤街醉人 提交于 2019-12-06 09:46:01

Just pass your Dart function into JavaScript and it'll automatically converted to a JavaScript function.

Dart:

import 'dart:js';

myCallback(data) {
  print('received $data');
}

main() {
  context.callMethod('mJsFunction', [myCallback]);
}

JS:

function myJsFunction(callback) {
  callback('some data');
}

For data passed to the Dart callback, many types will be automatically converted (see the list here: http://api.dartlang.org/docs/releases/latest/dart_js.html) and other types will give you a JsObject proxy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!