watchIt<T extends Listenable> function

T watchIt<T extends Listenable>({
  1. String? instanceName,
  2. GetIt? getIt,
})

watchIt observes any Listenable registered in get_it and triggers a rebuild whenever it notifies a change. Its basically a shortcut for watch(di<T>()) instanceName is the optional name of the instance if you registered it with a name in get_it. getIt is the optional instance of get_it to use if you don't want to use the default one. 99% of the time you won't need this.

Implementation

T watchIt<T extends Listenable>({String? instanceName, GetIt? getIt}) {
  assert(_activeWatchItState != null,
      'watchIt can only be called inside a build function within a WatchingWidget or a widget using the WatchItMixin');
  final getItInstance = getIt ?? di;
  final parentObject = getItInstance<T>(instanceName: instanceName);
  _activeWatchItState!.watchListenable(parentOrListenable: parentObject);
  return parentObject;
}