maybeOf<T> static method

T? maybeOf<T>(
  1. BuildContext context
)

Obtains the provided resource of type T from the widget tree, if available.

This method searches up the widget tree for a JoltProvider of type T and returns its provided resource. Returns null if no provider is found.

Example

final store = JoltProvider.maybeOf<MyStore>(context);
if (store != null) {
  // Use the store
}

Implementation

static T? maybeOf<T>(BuildContext context) {
  return context
      .dependOnInheritedWidgetOfExactType<_JoltProviderData<T>>()
      ?.data;
}