of<Injection extends RearchInjection<Injection, T>, T> static method

T of<Injection extends RearchInjection<Injection, T>, T>(
  1. BuildContext context
)

The state from the closest instance of the provided RearchInjection that encloses the given context.

You will normally use this function to implement an of function in your derived classes.

Will throw if the provided RearchInjection is not found in the given context.

See also:

  • maybeOf, which is a similar function, except that it will return null if the provided RearchInjection is not found in the given context.

Implementation

static T of<Injection extends RearchInjection<Injection, T>, T>(
  BuildContext context,
) {
  final widget = context.dependOnInheritedWidgetOfExactType<
      _RearchInjectionInheritedWidget<Injection, T>>();
  assert(widget != null, 'No $Injection in the widget tree above context!');
  return widget!.data;
}