of<T extends OrbitStore> static method

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

Returns the nearest ancestor OrbitScope<T>'s store.

Throws a FlutterError if there's no OrbitScope<T> above context — wrap the relevant widget in one, or use Orbit.use<T>() for the app-wide singleton instead.

Pass listen: false to read the store without subscribing this widget to rebuild on every change — e.g. inside a callback like onPressed, rather than directly in build.

Implementation

static T of<T extends OrbitStore>(
  BuildContext context, {
  bool listen = true,
}) {
  final store = maybeOf<T>(context, listen: listen);
  if (store == null) {
    throw FlutterError(
      'OrbitScope.of<$T>() was called with a context that has no '
      'OrbitScope<$T> above it.\n'
      'Wrap the relevant widget in OrbitScope<$T>(create: () => ..., '
      'child: ...), or use Orbit.use<$T>() for the app-wide singleton.',
    );
  }
  return store;
}