loadNetworkTexture static method

Future<GTexture> loadNetworkTexture(
  1. String url, {
  2. int? width,
  3. int? height,
  4. double resolution = 1.0,
  5. String? cacheId,
  6. NetworkEventCallback? onComplete,
  7. NetworkEventCallback? onProgress,
  8. NetworkEventCallback? onError,
})

Loads a network texture from the given URL with optional width, height, resolution, and cacheId. If the texture is already in the cache, it is returned directly. Otherwise, the texture is downloaded and converted into a GTexture instance.

Throws a FlutterError if the texture can't be loaded.

Implementation

static Future<GTexture> loadNetworkTexture(
  String url, {
  int? width,
  int? height,
  double resolution = 1.0,
  String? cacheId,
  NetworkEventCallback? onComplete,
  NetworkEventCallback? onProgress,
  NetworkEventCallback? onError,
}) async {
  if (cacheId != null && textureCache.containsKey(cacheId)) {
    return textureCache[cacheId]!;
  }
  final response = await NetworkImageLoader.load(
    url,
    width: width,
    height: height,
    scale: resolution,
    onComplete: onComplete,
    onProgress: onProgress,
    onError: onError,
  );
  if (response.isError) {
    throw FlutterError(
      'Unable to load network texture $url.\nReason: ${response.reasonPhrase}',
    );
  }
  if (response.isImage && cacheId != null) {
    textureCache[cacheId] = response.texture!;
  }
  return response.texture!;
}