genJoinJsMethod method

String genJoinJsMethod(
  1. List<String> bridgeNames, {
  2. required String method,
  3. dynamic returnValue,
})

生成加入js方法 methodjs方法带参数不带返回类型 returnValuejs方法返回值

Implementation

String genJoinJsMethod(List<String> bridgeNames, {required String method, dynamic returnValue}) {
  var hasMatch = new RegExp("[(](.*)[)]").hasMatch(method);
  if (!hasMatch) {
    return "";
  }
  dynamic value;
  var type = returnValue.runtimeType.toString().toLowerCase();
  if (type == "bool" || type == "int" || type == "double") {
    value = returnValue;
  } else {
    value = '"$returnValue"';
  }
  var filter = new RegExp("[(](.*)[)]").firstMatch(method);
  var group = filter?.group(0);
  if (group.isEmptyString) {
    return "";
  }
  var _method = method.replaceAll(group!, "");
  var buffer = new StringBuffer('joinJsMethod9794([');
  bridgeNames.forEach((String bridge) {});
  for (int i = 0; i < bridgeNames.length; i++) {
    buffer.write("'${bridgeNames[i]}'");
    if ((i + 1) < bridgeNames.length) {
      buffer.write(",");
    }
  }
  buffer.write("], '$_method', function $group { return $value; });");
  return buffer.toString();
}