Comment on page
AssetBundleis a container that provides asynchronous access to application resources (e.g., images, strings, fonts). Resources are associated with a string-based key and can be retrieved as bytes (via
AssetBundle.load), a string (via
AssetBundle.loadString), or structured data (via
AssetBundle.loadStructuredData). A variety of subclasses support different methods for obtaining assets (e.g.,
NetworkAssetBundle). Some bundles also support caching; if so, keys can be evicted from the bundle’s cache (via
CachingAssetBundlecaches strings and structured data throughout the application’s lifetime (unless explicitly evicted). Binary data is not cached since the higher level methods are built atop
AssetBundle.load, and the final representation is more efficient to store.
- Every application is associated with a
AssetBundlecontains the resources that were packaged when the application was built (i.e., as specified by
pubspec.yaml). Though this bundle can be queried directly,
DefaultAssetBundleprovides a layer of indirection so that different bundles can be substituted (e.g., for testing or localization).
NetworkAssetBundleloads resources over the network. It does not implement caching; presumably, this is provided by the network layer. It provides a thin wrapper around dart’s
CachingAssetBundlesubclass that fetches resources from a platform-specific application directory via platform messaging (specifically,