loadScript function

Future<void> loadScript()

Implementation

Future<void> loadScript() async {
  if (_scriptLoaderCompleter != null) {
    return _scriptLoaderCompleter!.future;
  }

  _scriptLoaderCompleter = Completer();

  final assetManager = AssetManager();
  final script = ScriptElement();
  script.src = assetManager
      .getAssetUrl('packages/flutter_avif_web/web/avif_decoder.loader.js');
  document.head!.append(script);
  await script.onLoad.first;

  final initBindgen = promiseToFuture(_initBindgen(assetManager
      .getAssetUrl('packages/flutter_avif_web/web/avif_decoder.worker.js')));
  await initBindgen;

  _scriptLoaderCompleter!.complete();
}