pingora<T extends Pingora> method

T pingora<T extends Pingora>()

Retrieves the nearest Pingora instance of type T from an ancestor PingoraScope in the widget tree.

Once you have the instance, you can call any Pingora method directly:

final model = context.pingora<CounterModel>();

model.subscribe(listener);      // listen for state changes
model.ping();                   // notify all listeners
model.unsubscribe(listener);   // stop listening
model.dispose();                // shut down permanently

Throws an AssertionError if no matching PingoraScope is found above in the widget tree.

Implementation

T pingora<T extends Pingora>() {
  final inherited =
      dependOnInheritedWidgetOfExactType<_PingoraInherited<T>>();
  assert(
    inherited != null,
    'No PingoraScope<$T> found above in the widget tree. '
    'Ensure the widget is wrapped in a PingoraScope<$T>.',
  );
  return inherited!.pingora;
}