maybeOf<T> static method

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

Retrieves the nearest SolidProvider of type T from the widget tree. Returns null if no provider is found.

Implementation

static T? maybeOf<T>(BuildContext context, {bool listen = true}) {
  if (listen) {
    return context
        .dependOnInheritedWidgetOfExactType<InheritedSolidProvider<T>>()
        ?.data;
  }
  final provider = context
      .getElementForInheritedWidgetOfExactType<InheritedSolidProvider<T>>()
      ?.widget;
  return (provider as InheritedSolidProvider<T>?)?.data;
}