loadJsFileIfNeeded function

Future<void> loadJsFileIfNeeded()

Implementation

Future<void> loadJsFileIfNeeded() async {
  if (kIsWeb && !_jsloaded) {
    final stockfishScript = html.document.createElement("script");
    stockfishScript.setAttribute("src", "${jsPath}flutter_stockfish_plugin.js");
    html.document.head?.append(stockfishScript);

    await stockfishScript.onLoad.first;

    final jsBindingsScript = html.document.createElement("script");
    jsBindingsScript.setAttribute("src", "${jsPath}js_bindings.js");
    html.document.head?.append(jsBindingsScript);

    await jsBindingsScript.onLoad.first;

    _jsloaded = true;
  }
  await _stockfishWaitReady();
}