addHandler method

void addHandler(
  1. String methodName,
  2. JavascriptMessageHandler onMessageReceived
)

添加脚本注册方法

Implementation

void addHandler(String methodName, JavascriptMessageHandler onMessageReceived) {
  if (methodName.isEmpty) {
    return;
  }
  JavascriptChannel channel = new JavascriptChannel(
      name: methodName,
      onMessageReceived: (JavascriptMessage message) {
        var callReceive = _JavascriptCallReceive(methodName, message, onMessageReceived);
        callReceive.call();
      });
  if (jsChannels.containsKey(methodName)) {
    jsChannels[methodName] = channel;
  } else {
    jsChannels.putIfAbsent(methodName, () => channel);
  }
}