ResourceLoader class abstract

This class is used to load and cache different types of resources, including SVG files, images, shaders, and texture atlases. It also provides a method to clear the cache of all loaded resources.

Constructors

ResourceLoader()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

atlasCache Map<String, GTextureAtlas>
A static cache of texture atlases. The cache is a map, where the key is a unique identifier for the atlas, and the value is an instance of the GTextureAtlas class.
getter/setter pair
gifCache Map<String, GifAtlas>
A static cache of GIF images. The cache is a map, where the key is a unique identifier for the GIF, and the value is an instance of the GifAtlas class.
getter/setter pair
shaderCache Map<String, FragmentProgram>
A static cache of fragment shaders. The cache is a map, where the key is a unique identifier for the shader, and the value is an instance of the FragmentProgram class.
getter/setter pair
svgCache Map<String, SvgData>
A static cache of SVG data. The cache is a map, where the key is a unique identifier for the SVG, and the value is an instance of the SvgData class.
getter/setter pair
textureCache Map<String, GTexture>
A static cache of texture data. The cache is a map, where the key is a unique identifier for the texture, and the value is an instance of the GTexture class.
getter/setter pair

Static Methods

clearCache() → void
Clears all loaded resource caches.
getAtlas(String cacheId) GTextureAtlas?
Retrieves a cached GTextureAtlas instance associated with the given cacheId. Returns null if no GTextureAtlas is found.
getGif(String cacheId) GifAtlas?
Retrieves a cached GifAtlas instance associated with the given cacheId. Returns null if no GifAtlas is found.
getShader(String cacheId) FragmentProgram?
Returns the loaded fragment shader program corresponding to the given cacheId. If the cacheId is not present in the shaderCache, null is returned.
getSvg(String cacheId) SvgData?
This method returns an SvgData instance for a given cacheId, or null if the cacheId is not present in the svgCache cache.
getTexture(String cacheId) GTexture?
This method returns a GTexture instance for a given cacheId, or null if the cacheId is not present in the textureCache cache.
loadBinary(String path) Future<ByteData>
Loads a binary file from local assets.
loadGif(String path, {double resolution = 1.0, String? cacheId}) Future<GifAtlas>
Loads a GifAtlas instance from the given asset path. If a cacheId is provided, the resulting GifAtlas is stored in the cache with the given ID. If the cacheId already exists in the cache, the cached GifAtlas is returned. The resolution parameter controls the scaling of the gif's frames.
loadImage(String path, {int? targetWidth, int? targetHeight}) Future<Image>
Loads an image from local assets.
loadJson(String path) Future
Loads a JSON file from local assets.
loadNetworkSvg(String url, {String? cacheId, NetworkEventCallback? onComplete, NetworkEventCallback? onProgress, NetworkEventCallback? onError}) Future<SvgData>
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.
loadNetworkTexture(String url, {int? width, int? height, double resolution = 1.0, String? cacheId, NetworkEventCallback? onComplete, NetworkEventCallback? onProgress, NetworkEventCallback? onError}) Future<GTexture>
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.
loadNetworkTextureSimple(String url, {int? width, int? height, double resolution = 1.0, String? cacheId}) Future<GTexture>
Loads an image from a network URL and returns a GTexture object. The image is loaded asynchronously, and the returned Future is completed with the GTexture object when the image is fully loaded. The width and height parameters can be used to resize the image. The resolution parameter can be used to scale the image. If cacheId is provided, the loaded texture will be added to the texture cache using cacheId as the key. If the cacheId already exists in the cache, the cached texture will be returned instead.
loadShader(String path, [String? cacheId]) Future<FragmentProgram>
Loads a shader program from the given path. If the program is already in the cache, it is returned directly. Otherwise, the program is loaded from the given path and stored in the cache (with the optional cacheId) for future use.
loadString(String path) Future<String>
Loads a string (plain text) file from local assets.
loadSvg(String path, [String? cacheId]) Future<SvgData>
A static method to load an SVG image from a file.
loadTexture(String path, [double resolution = 1.0, String? cacheId]) Future<GTexture>
Loads a texture from the given path with optional resolution and cacheId. If the texture is already in the cache, it is returned directly. Otherwise, the image at the given path is loaded and converted into a GTexture instance.
loadTextureAtlas(String imagePath, {String? dataPath, double resolution = 1.0, String? cacheId}) Future<GTextureAtlas>
Loads a texture atlas from an image and XML/JSON data file.