loadFromUrlString static method

Future<WasmSqlite3> loadFromUrlString(
  1. String url, {
  2. Map<String, String>? headers,
  3. WasmModuleLoader? loader,
})

Loads a web version of the sqlite3 libraries.

The native wasm library for sqlite3 is loaded from the url with the desired headers through a fetch request.

Using this over loadFromUrl might reduce compiled JS sizes for apps which otherwise don't use URLs.

Implementation

static Future<WasmSqlite3> loadFromUrlString(
  String url, {
  Map<String, String>? headers,
  WasmModuleLoader? loader,
}) async {
  web.RequestInit? options;

  if (headers != null) {
    final headersJs = JSObject();
    headers.forEach((key, value) {
      headersJs[key] = value.toJS;
    });

    options = web.RequestInit(headers: headersJs);
  }

  final jsUri = web.URL(url, (globalContext['location'] as web.URL).href);
  final response = await fetch(jsUri, options).toDart;
  return _load(response, loader);
}