of<T extends BlocBase> static method

T of<T extends BlocBase>(
  1. BuildContext context
)

Obtains the nearest Provider<T> up its widget tree and returns its value.

If listen is true, later value changes will trigger a new State.build to widgets, and State.didChangeDependencies for StatefulWidget.

listen: false is necessary to be able to call Provider.of inside State.initState or the create method of providers like so:

Provider(
  create: (context) {
    return Model(Provider.of<Something>(context, listen: false)),
  },
)

Implementation

static T of<T extends BlocBase>(BuildContext context) =>
    Provider.of<T>(context);