asset_cache 1.0.1 copy "asset_cache: ^1.0.1" to clipboard
asset_cache: ^1.0.1 copied to clipboard

Load and cache binary asset of any type given a decoder. Built-in support for images, json and more.

asset_cache #

asset_cache will load and cache any asset of type T given a decoder.

I made this since CachingAssetBundle does not cache binary data.

Binary resources (from load) are not cached.

Usage #

Describe assets in your pubspec.yaml:

  assets:
     - assets/images/
     - assets/json/

Create asset cache objects with an optional basePath to avoid using full asset paths:

final imageCache = ImageAssetCache(basePath: "assets/images/");
final jsonCache = JsonAssetCache(basePath: "assets/json/");

Load and cache assets using load, which returns a Future<T>:

final image = await imageCache.load('sprite.png')
final json = await jsonCache.load('sprite.json')

We include the following AssetCache implementations:

  • ImageAssetCache
  • JsonAssetCache
  • StringAssetCache
  • ByteDataAssetCache

Custom AssetCache #

Create a custom asset cache by inheriting from AssetCache and pass it a AssetDecoder.

You can also inherit from GenericCache and override loadAsset, if you don't want to load from a AssetBundle.

More #

See example and test.

41
likes
160
pub points
88%
popularity

Publisher

verified publisherapptakk.com

Load and cache binary asset of any type given a decoder. Built-in support for images, json and more.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path

More

Packages that depend on asset_cache