of<T> static method

T of<T>(
  1. BuildContext context
)

Retrieves a dependency of type T from the nearest IoC provider in the widget tree.

Throws an assertion error if the dependency is not found.

Implementation

static T of<T>(BuildContext context) {
  T? dependency = maybeOf<T>(context);
  assert(
    dependency != null,
    "The requested dependency <$T> is not registered in the widget tree.",
  );
  return dependency!;
}