watchIt<T extends Listenable> function
T
watchIt<T extends Listenable>({})
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.
param1 and param2 are forwarded to get_it and are only valid if T was
registered with registerCachedFactoryParam. If the params change between
builds and get_it returns a different instance, the widget automatically
switches its subscription to the new instance.
Implementation
T watchIt<T extends Listenable>({
String? instanceName,
GetIt? getIt,
dynamic param1,
dynamic param2,
}) {
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;
_debugCheckRegistration<T>(
getItInstance, 'watchIt', instanceName, param1, param2);
final parentObject = getItInstance<T>(
instanceName: instanceName, param1: param1, param2: param2);
_activeWatchItState!.watchListenable(parentOrListenable: parentObject);
return parentObject;
}