setupBridge method

  1. @override
bool setupBridge(
  1. String channelName,
  2. dynamic fn(
    1. dynamic args
    )
)
override

Implementation

@override
bool setupBridge(String channelName, dynamic Function(dynamic args) fn) {
  // final channelFunctionCallbacks =
  //     JavascriptRuntime.channelFunctionsRegistered[getEngineInstanceId()];
  // if (channelFunctionCallbacks.keys.contains(channelName)) return false;

  // channelFunctionCallbacks[channelName] = fn;
  _flutterJs.addChannel(channelName, (args) {
    final mapArgs = json.decode(args!);
    final res = fn(mapArgs);
    this.evaluate("""
       FLUTTERJS_pendingMessages['${mapArgs['id']}'].resolve(${json.encode(res)});
    """
        .trim());
    return Future.value(res);
  }, dartChannelAddress: 'http://$_dartAddress');

  return true;
}