ResourceLoader class abstract

Manages loading and caching of various resource types including SVGs, images, shaders, and texture atlases.

Key features:

  • Caches resources to avoid reloading
  • Supports local assets and network resources
  • Handles SVG parsing and rendering
  • Manages texture atlases and GIF animations
  • Provides shader loading capabilities

Usage:

// Load a texture from assets
final texture = await ResourceLoader.loadTexture('assets/image.png');

// Load and cache a network image
final networkTexture = await ResourceLoader.loadNetworkTexture(
  'https://example.com/image.png',
  cacheId: 'unique-id'
);

// Clear all cached resources
ResourceLoader.clearCache();

Constructors

ResourceLoader.new()

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>
Cache for texture atlases. Keys are unique identifiers, values are GTextureAtlas instances.
getter/setter pair
gifCache Map<String, GifAtlas>
Cache for GIF animations. Keys are unique identifiers, values are GifAtlas instances.
getter/setter pair
shaderCache Map<String, FragmentProgram>
Cache for fragment shader programs. Keys are unique identifiers, values are compiled FragmentProgram objects.
getter/setter pair
svgDataCache Map<String, SvgData>
Cache for parsed SVG data. Keys are unique identifiers, values are parsed SvgData objects.
final
svgStringCache Map<String, String>
Cache for raw SVG string data. Keys are unique identifiers, values are the SVG strings.
getter/setter pair
textureCache Map<String, GTexture>
Cache for texture data. Keys are unique identifiers, values are GTexture instances.
getter/setter pair

Static Methods

clearCache() → void
Clears all cached resources and disposes of any allocated memory.
getAtlas(String cacheId) GTextureAtlas?
Retrieves a cached texture atlas by its ID.
getGif(String cacheId) GifAtlas?
Retrieves a cached GIF animation by its ID.
getShader(String cacheId) FragmentProgram?
Retrieves a cached shader program by its ID.
getSvgData(String cacheId) SvgData?
Retrieves cached SVG data by its ID.
getSvgString(String cacheId) String?
Retrieves a cached SVG string by its ID.
getTexture(String cacheId) GTexture?
Retrieves a cached texture by its ID.
loadBinary(String path) Future<ByteData>
Loads binary data from a local asset file.
loadGif(String path, {double resolution = 1.0, String? cacheId}) Future<GifAtlas>
Loads and caches a GIF animation from a local asset file.
loadImage(String path, {int? targetWidth, int? targetHeight}) Future<Image>
Loads an image from a local asset file with optional resizing.
loadJson(String path) Future
Loads and parses a JSON file from a local asset.
loadNetworkSvgData(String url, {String? cacheId, NetworkEventCallback? onComplete, NetworkEventCallback? onProgress, NetworkEventCallback? onError}) Future<SvgData>
Loads and parses an SVG from a network URL into SvgData.
loadNetworkSvgString(String url, {String? cacheId, NetworkEventCallback? onComplete, NetworkEventCallback? onProgress, NetworkEventCallback? onError}) Future<String>
Loads an SVG string from a network URL.
loadNetworkTexture(String url, {int? width, int? height, double resolution = 1.0, String? cacheId, NetworkEventCallback? onComplete, NetworkEventCallback? onProgress, NetworkEventCallback? onError}) Future<GTexture>
Loads and optionally caches a texture from a network URL.
loadNetworkTextureSimple(String url, {int? width, int? height, double resolution = 1.0, String? cacheId}) Future<GTexture>
Simplified version of loadNetworkTexture without progress tracking.
loadShader(String path, [String? cacheId]) Future<FragmentProgram>
Loads and optionally caches a shader program from a local asset.
loadString(String path) Future<String>
Loads a text file from a local asset.
loadTexture(String path, [double resolution = 1.0, String? cacheId]) Future<GTexture>
Loads and optionally caches a texture from a local asset.
loadTextureAtlas(String imagePath, {String? dataPath, double resolution = 1.0, String? cacheId}) Future<GTextureAtlas>
Loads and optionally caches a texture atlas from image and data files.
setSvgDataParser(SvgStringToDataCallback callback) → void
Sets the parser function used to convert SVG strings into SvgData objects.