rootBundle top-level property

AssetBundle rootBundle

The AssetBundle from which this application was loaded.

The rootBundle 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
   - images/hamilton.jpeg
   - images/lafayette.jpeg

Rather than using rootBundle directly, consider obtaining the AssetBundle for the current BuildContext using DefaultAssetBundle.of. This layer of indirection lets ancestor widgets substitute a different AssetBundle at runtime (e.g., for testing or localization) 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:


final AssetBundle rootBundle = _initRootBundle();