watchId<T extends Object?> method

T watchId<T extends Object?>(
  1. String id, [
  2. ListenStates<T>? listenStates
])

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

final appController = context.watchId<AppController>("UniqueId");
final appControllerWatchHook = context.watchId<AppController>(
  "UniqueId",
  (inst) => [inst.stateA],
);
final appControllerNullable = context.wathId<AppController?>("UniqueId");

If T is nullable and no matching instance is found, watchId 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, id: id, listenStates: listenStates);

Implementation

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