loadLavaAsset method
Loads a Lava animation from the specified asset path.
The assetPath should point to a directory containing a manifest.json file
and the required image atlas frames. This directory must be included in the
pubspec.yaml assets section.
Example:
controller.loadLavaAsset('assets/animations/fire_loop');
Implementation
Future<void> loadLavaAsset(String assetPath) async {
final manifestData = await rootBundle.loadString("$assetPath/manifest.json");
final manifest = LavaManifest.fromJson(jsonDecode(manifestData));
final images = <ui.Image>[];
for (final image in manifest.images) {
final imageData = await rootBundle.load("$assetPath/${image.url}");
final codec = await ui.instantiateImageCodec(imageData.buffer.asUint8List());
final frame = await codec.getNextFrame();
images.add(frame.image);
}
asset = LavaAsset(
images: images,
manifest: manifest,
);
frameIndex = 0;
notifyListeners();
}