requireNativeByPackage static method

Future<bool> requireNativeByPackage(
  1. List<String> modules,
  2. String jsLocation,
  3. dynamic jsSubPath, {
  4. String? globalJSVariableName,
})

Tries to load a module using native AMD using package/module configuration. 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> requireNativeByPackage(
    List<String> modules, String jsLocation, jsSubPath,
    {String? globalJSVariableName}) async {
  await load();

  var nativePresent = await isNativeImplementationPresent();

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

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

  var completer = Completer<bool>();

  context.callMethod('__AMDJS__requireModuleNative_byPackage', [
    JsObject.jsify(modules),
    jsLocation,
    jsSubPath,
    globalJSVariableName,
    (r) {
      var ok = r == true;
      _log(true, "Modules '$modules' loaded[by package]> ok: $ok");
      completer.complete(ok);
    }
  ]) as bool?;

  return completer.future;
}