requireNativeByPath static method

Future<bool> requireNativeByPath(
  1. String module,
  2. String jsFullPath, {
  3. String? globalJSVariableName,
})

Tries to load a module using native AMD using jsFullPath. Is recommended to use the function require, that calls requireNative only if is really needed.

Throws StateError if native mode is not detected.

Implementation

static Future<bool> requireNativeByPath(String module, String jsFullPath,
    {String? globalJSVariableName}) async {
  await load();

  var nativePresent = await isNativeImplementationPresent();

  if (!nativePresent) {
    throw StateError('AMD native implementation not present');
  }

  if (jsFullPath.toLowerCase().endsWith('.js')) {
    jsFullPath = jsFullPath.substring(0, jsFullPath.length - 3);
  }

  var completer = Completer<bool>();

  context.callMethod('__AMDJS__requireModuleNative_byPath', [
    module,
    jsFullPath,
    globalJSVariableName,
    (r) {
      var ok = r == true;
      _log(true, "Module '$module' loaded[by path]> ok: $ok");
      completer.complete(ok);
    }
  ]) as bool?;

  return completer.future;
}