loadNetworkTexture static method
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!;
}