loadFromAsset static method

Future<AnimatedVectorData> loadFromAsset(
  1. String assetName, {
  2. AssetBundle? bundle,
  3. String? package,
})

Dynamically load an AnimatedVectorData from a json Shape Shifter file bundled in the app or other packages assets. The package parameter allows to specify a specific package to obtain the asset from.

The returned instance needs to be stored somewhere in order to be used as this method doesn't store anything inside a cache or similar.

Where possible prefer to use code generation from animated_vector_gen as it's syncronous and allows for const instances to be created.

Implementation

static Future<AnimatedVectorData> loadFromAsset(
  String assetName, {
  AssetBundle? bundle,
  String? package,
}) {
  final assetKey =
      package != null ? "packages/$package/$assetName" : assetName;

  return (bundle ?? rootBundle).loadStructuredData(
    assetKey,
    (value) async => ShapeShifterConverter.toAVD(value),
  );
}