setup method

Future<void> setup()

Implementation

Future<void> setup() async {
  jsRuntime = getJavascriptRuntime();
  var ajvIsLoaded = jsRuntime.evaluate("""
        var ajvIsLoaded = (typeof ajv == 'undefined') ? "0" : "1";
        ajvIsLoaded;
      """).stringResult;
  debugPrint("AJV is Loaded $ajvIsLoaded");

  if (ajvIsLoaded == "0") {
    try {
      jsRuntime.evaluate("""var window = global = globalThis;""");
      final ajvJS = await rootBundle
          .loadString("packages/flutter_ajv/assets/js/ajv.js");
      jsRuntime.evaluate(ajvJS);
    } catch (e) {
      debugPrint('Failed to init js engine: ${e.toString()}');
    }
  }
}