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

outdated

load and cache any local asset type given a decoder

asset_cache #

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

Using CachingAssetBundle, Flutter will not cache binary resources. We therefor do it ourselves, using AssetBundle.load.

You can create your own asset cache by inheriting from AssetCache and give it a decoder or by inheriting from GenericCache and overriding loadAsset.

asset_cache comes with singletons for loading various resources:

  • ImageAssets
  • JsonAssets
  • StringAssets
  • ByteDataAssets

Usage #

Add asset_cache to your pubspec.yaml:

dependencies:
  asset_cache:

Describe assets in your pubspec.yaml:

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

You can set the AssetCache.basePath to avoid using full paths for assets:

JsonAssets.instance.basePath = "assets/json/";

Now load and cache assets using load, which returns a Future<T>.

final json = await JsonAssets.instance.load('sprite.json')

See example and test for more.

Based on CachingAssetBundle.

39
likes
0
pub points
87%
popularity

Publisher

verified publisherapptakk.com

load and cache any local asset type given a decoder

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on asset_cache