AssetBundle class Null safety

A collection of resources used by the application.

Asset bundles contain resources, such as images and strings, that can be used by an application. Access to these resources is asynchronous so that they can be transparently loaded over a network (e.g., from a NetworkAssetBundle) or from the local file system without blocking the application's user interface.

Applications have a rootBundle, which contains the resources that were packaged with the application when it was built. To add resources to the rootBundle for your application, add them to the assets subsection of the flutter section of your application's pubspec.yaml manifest.

For example:

name: my_awesome_application
flutter:
  assets:
   - images/hamilton.jpeg
   - images/lafayette.jpeg

Rather than accessing the rootBundle global static directly, consider obtaining the AssetBundle for the current BuildContext using DefaultAssetBundle.of. This layer of indirection lets ancestor widgets substitute a different AssetBundle (e.g., for testing or localization) at runtime rather than directly replying upon the rootBundle created at build time. For convenience, the WidgetsApp or MaterialApp widget at the top of the widget hierarchy configures the DefaultAssetBundle to be the rootBundle.

See also:

Implementers

Constructors

AssetBundle()

Properties

hashCode int
The hash code for this object.
read-onlyinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

clear() → void
If this is a caching asset bundle, clear all cached data.
evict(String key) → void
If this is a caching asset bundle, and the given key describes a cached asset, then evict the asset from the cache so that the next time it is loaded, the cache will be reread from the asset bundle.
load(String key) Future<ByteData>
Retrieve a binary resource from the asset bundle as a data stream.
loadBuffer(String key) Future<ImmutableBuffer>
Retrieve a binary resource from the asset bundle as an immutable buffer.
loadString(String key, {bool cache = true}) Future<String>
Retrieve a string from the asset bundle.
loadStructuredData<T>(String key, Future<T> parser(String value)) Future<T>
Retrieve a string from the asset bundle, parse it with the given function, and return the function's result.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited