network static method

Future<MorphIconData> network(
  1. Uri url, {
  2. Map<String, String>? headers,
  3. bool fit = true,
  4. double grid = 24,
})

Fetches an SVG over HTTP.

Uses the SDK's own client — this package takes no dependencies — which means it is unavailable on the web. Fetch the bytes yourself and use memory there.

The result is cached by URL for the life of the process; call clearCache if you are loading icons that change.

Implementation

static Future<MorphIconData> network(
  Uri url, {
  Map<String, String>? headers,
  bool fit = true,
  double grid = 24,
}) {
  final k = _key('net', url.toString(), fit, grid);
  final hit = _cache[k];
  if (hit != null) return SynchronousFuture<MorphIconData>(hit);
  return _pending[k] ??= () async {
    try {
      final bytes = await loadUrlBytes(url, headers);
      return _parse(k, utf8.decode(bytes, allowMalformed: true), fit, grid);
    } finally {
      _pending.remove(k);
    }
  }();
}