loadNetworkSvg static method

Future<SvgData> loadNetworkSvg(
  1. String url, {
  2. String? cacheId,
  3. NetworkEventCallback? onComplete,
  4. NetworkEventCallback? onProgress,
  5. NetworkEventCallback? onError,
})

Loads an SVG from a network URL and returns a SvgData object. The SVG is loaded asynchronously, and the returned Future is completed with the SvgData object when the SVG is fully loaded. If cacheId is provided, the loaded SVG will be added to the SVG cache using cacheId as the key.

Throws a FlutterError if the SVG cannot be loaded.

Implementation

static Future<SvgData> loadNetworkSvg(
  String url, {
  String? cacheId,
  NetworkEventCallback? onComplete,
  NetworkEventCallback? onProgress,
  NetworkEventCallback? onError,
}) async {
  final response = await NetworkImageLoader.loadSvg(
    url,
    onComplete: onComplete,
    onProgress: onProgress,
    onError: onError,
  );
  if (response.isError) {
    throw FlutterError(
        'Unable to load SVG $url.\nReason: ${response.reasonPhrase}');
  }
  if (response.isSvg && cacheId != null) {
    svgCache[cacheId] = response.svgData!;
  }
  return response.svgData!;
}