of method

AssetBundle of (
  1. BuildContext context
)

The bundle from the closest instance of this class that encloses the given context.

If there is no DefaultAssetBundle ancestor widget in the tree at the given context, then this will return the rootBundle.

Typical usage is as follows:

AssetBundle bundle = DefaultAssetBundle.of(context);

Implementation

static AssetBundle of(BuildContext context) {
  final DefaultAssetBundle result = context.dependOnInheritedWidgetOfExactType<DefaultAssetBundle>();
  return result?.bundle ?? rootBundle;
}