fetch static method

Future<String?> fetch(
  1. String url,
  2. String cacheMode
)

Downloads url with the given HTTP cache mode ("no-store", "force-cache", "reload", ...). Null on any failure, so callers can treat "offline" and "missing" the same way.

Implementation

static Future<String?> fetch(String url, String cacheMode) async {
  try {
    final web.Response response = await web.window.fetch(url.toJS, web.RequestInit(cache: cacheMode)).toDart;
    if (!response.ok) return null;
    return (await response.text().toDart).toDart;
  } catch (_) {
    return null;
  }
}