maybeOf<T extends OrbitStore> static method

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

Returns the nearest ancestor OrbitScope<T>'s store, or null if no such ancestor exists.

Implementation

static T? maybeOf<T extends OrbitStore>(
  BuildContext context, {
  bool listen = true,
}) {
  if (listen) {
    return context
        .dependOnInheritedWidgetOfExactType<_OrbitScopeInherited<T>>()
        ?.store;
  }
  final element = context
      .getElementForInheritedWidgetOfExactType<_OrbitScopeInherited<T>>();
  return (element?.widget as _OrbitScopeInherited<T>?)?.store;
}