loadFromAssetBundle static method

Future<AssetManifest> loadFromAssetBundle(
  1. AssetBundle bundle
)

Loads asset manifest data from an AssetBundle object and creates an AssetManifest object from that data.

Implementation

static Future<AssetManifest> loadFromAssetBundle(AssetBundle bundle) {
  // The AssetManifest file contains binary data.
  //
  // On the web, the build process wraps this binary data in json+base64 so
  // it can be transmitted over the network without special configuration
  // (see #131382).
  if (kIsWeb) {
    // On the web, the AssetManifest is downloaded as a String, then
    // json+base64-decoded to get to the binary data.
    return bundle.loadStructuredData(_kAssetManifestWebFilename, (String jsonData) async {
      // Decode the manifest JSON file to the underlying BIN, and convert to ByteData.
      final ByteData message = ByteData.sublistView(base64.decode(json.decode(jsonData) as String));
      // Now we can keep operating as usual.
      return _AssetManifestBin.fromStandardMessageCodecMessage(message);
    });
  }
  // On every other platform, the binary file contents are used directly.
  return bundle.loadStructuredBinaryData(_kAssetManifestFilename, _AssetManifestBin.fromStandardMessageCodecMessage);
}