maybeOf static method

GridViewObserverState? maybeOf(
  1. BuildContext context, {
  2. String? tag,
})

Returning the closest instance of this class that encloses the given context.

If you give a tag, it will give priority find the corresponding instance of this class with the given tag and return it.

If there is no ObserverWidget widget, then null is returned.

Calling this method will create a dependency on the closest ObserverWidget in the context, if there is one.

See also:

  • ObserverWidget.of, which is similar to this method, but asserts if no ObserverWidget instance is found.

Implementation

static GridViewObserverState? maybeOf(
  BuildContext context, {
  String? tag,
}) {
  final _state = ObserverWidget.maybeOf<
      GridObserverController,
      GridViewObserveModel,
      GridViewOnceObserveNotification,
      GridViewObserver>(
    context,
    tag: tag,
  );
  if (_state is! GridViewObserverState) return null;
  return _state;
}