watchId<T extends Object?> method

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

Gets the dependency of T type by id from the closest ancestor of RtProvider and watchs changes to the dependency or the states(RtState) 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 dependency is found, watchId will return null.

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

This method is equivalent to calling:

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

Implementation

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