load method

  1. @override
Future<LottieComposition> load({
  1. BuildContext? context,
})
override

Implementation

@override
Future<LottieComposition> load({BuildContext? context}) {
  return sharedLottieCache.putIfAbsent(this, () async {
    final finalContext = context;
    final chosenBundle = bundle ??
        (finalContext != null
            ? DefaultAssetBundle.of(finalContext)
            : rootBundle);

    var data = await chosenBundle.load(keyName);

    LottieComposition composition;
    if (backgroundLoading) {
      composition =
          await compute(parseJsonBytes, (data.buffer.asUint8List(), decoder));
    } else {
      composition =
          await LottieComposition.fromByteData(data, decoder: decoder);
    }

    for (var image in composition.images.values) {
      image.loadedImage ??= await _loadImage(composition, image);
    }

    await ensureLoadedFonts(composition);

    return composition;
  });
}