Asset Management
How are assets managed?
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 (viaAssetBundle.load), a string (viaAssetBundle.loadString), or structured data (viaAssetBundle.loadStructuredData). A variety of subclasses support different methods for obtaining assets (e.g.,PlatformAssetBundle,NetworkAssetBundle). Some bundles also support caching; if so, keys can be evicted from the bundle’s cache (viaAssetBundle.evict).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 atopAssetBundle.load, and the final representation is more efficient to store.Every application is associated with a
rootBundle. ThisAssetBundlecontains the resources that were packaged when the application was built (i.e., as specified bypubspec.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).
How are assets fetched?
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’sHttpClient.PlatformAssetBundleis aCachingAssetBundlesubclass that fetches resources from a platform-specific application directory via platform messaging (specifically,Engine::HandleAssetPlatformMessage).
Last updated
Was this helpful?