ReadContext extension

Finds what a provider above provides.

Builder(
  builder: (context) =>
      Button('Buy', onPressed: () => context.read<Cart>().add('tea')),
)
on

Methods

read<T>() → T

Available on BuildContext, provided by the ReadContext extension

The T of the nearest provider of one above this context, without depending on it: for callbacks, as context.read<Counter>().increment() on a key, and for State.initState. A ProviderNotFoundException if there is none, unless T is nullable: then null.