watch<T extends Object?> method

T watch<T extends Object?>([
  1. ListenStates<T>? listenStates
])

Gets the instance of T type from the closest ancestor ReactterProvider and listens changes to the instance or the states(ReactterState) defined in first parameter(listenStates) to trigger rebuild of the Widget tree.

final appController = context.watch<AppController>();
final appControllerWatchStates = context.watch<AppController>(
  (inst) => [inst.stateA],
);
final appControllerNullable = context.wath<AppController?>();

If T is nullable and no matching instance is found, watch will return null.

If T is non-nullable and the instance obtained returned null, will throw ProviderNullException.

This method is equivalent to calling:

ReactterProvider.contextOf<T>(context, listenStates: listenStates);

Implementation

T watch<T extends Object?>([ListenStates<T>? listenStates]) {
  return ReactterProvider.contextOf<T>(this, listenStates: listenStates);
}