ofNullable<T> static method

T? ofNullable<T>(
  1. BuildContext context, {
  2. bool listen = false,
})

Retrieves the instance of type T from the widget tree, returns null if not found.

Implementation

static T? ofNullable<T>(
  BuildContext context, {
  bool listen = false,
}) {
  try {
    return Provider.of<T>(context, listen: listen);
  } on ProviderNotFoundException catch (_) {
    return null;
  }
}