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

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

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

You will normally use this function to implement a maybeOf function in your derived classes.

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

See also:

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

Implementation

static T? maybeOf<Injection extends RearchInjection<Injection, T>, T>(
  BuildContext context,
) {
  final widget = context.dependOnInheritedWidgetOfExactType<
      _RearchInjectionInheritedWidget<Injection, T>>();
  return widget?.data;
}