diff --git a/lib/src/watch_it.dart b/lib/src/watch_it.dart index ff7b317..8841188 100644 --- a/lib/src/watch_it.dart +++ b/lib/src/watch_it.dart @@ -133,11 +133,14 @@ R watchValue( bool allowObservableChange = false, String? instanceName, GetIt? getIt, + dynamic param1, + dynamic param2, }) { assert(_activeWatchItState != null, 'watchValue can only be called inside a build function within a WatchingWidget or a widget using the WatchItMixin'); final getItInstance = getIt ?? di; - final parentObject = getItInstance(instanceName: instanceName); + final parentObject = getItInstance( + instanceName: instanceName, param1: param1, param2: param2); final observedObject = _activeWatchItState!.watchListenable( parentOrListenable: parentObject, selector: selectProperty, @@ -171,13 +174,17 @@ R watchPropertyValue( T? target, String? instanceName, GetIt? getIt, + dynamic param1, + dynamic param2, }) { assert(_activeWatchItState != null, 'watchPropertyValue can only be called inside a build function within a WatchingWidget or a widget using the WatchItMixin'); late final T observedObject; final getItInstance = getIt ?? di; - final parentObject = target ?? getItInstance(instanceName: instanceName); + final parentObject = target ?? + getItInstance( + instanceName: instanceName, param1: param1, param2: param2); final R observedProperty = selectProperty(parentObject); assert( (observedProperty != null && observedProperty is! Listenable) || @@ -219,12 +226,16 @@ AsyncSnapshot watchStream( bool allowStreamChange = false, String? instanceName, GetIt? getIt, + dynamic param1, + dynamic param2, }) { assert(_activeWatchItState != null, 'watchStream can only be called inside a build function within a WatchingWidget or a widget using the WatchItMixin'); final getItInstance = getIt ?? di; - final parentObject = target ?? getItInstance(instanceName: instanceName); + final parentObject = target ?? + getItInstance( + instanceName: instanceName, param1: param1, param2: param2); // Validate target type when no select function is provided if (select == null && parentObject is! Stream) { @@ -271,12 +282,16 @@ AsyncSnapshot watchFuture( bool preserveState = true, bool allowFutureChange = false, GetIt? getIt, + dynamic param1, + dynamic param2, }) { assert(_activeWatchItState != null, 'watchFuture can only be called inside a build function within a WatchingWidget or a widget using the WatchItMixin'); final getItInstance = getIt ?? di; - final parentObject = target ?? getItInstance(instanceName: instanceName); + final parentObject = target ?? + getItInstance( + instanceName: instanceName, param1: param1, param2: param2); // Validate target type when no select function is provided if (select == null && parentObject is! Future) { @@ -330,12 +345,16 @@ void registerHandler({ bool executeImmediately = false, String? instanceName, GetIt? getIt, + dynamic param1, + dynamic param2, }) { assert(_activeWatchItState != null, 'registerHandler can only be called inside a build function within a WatchingWidget or a widget using the WatchItMixin'); final getItInstance = getIt ?? di; - final parentObject = target ?? getItInstance(instanceName: instanceName); + final parentObject = target ?? + getItInstance( + instanceName: instanceName, param1: param1, param2: param2); // Validate target type when no select function is provided if (select == null && parentObject is! Listenable) { @@ -375,12 +394,16 @@ void registerChangeNotifierHandler({ bool executeImmediately = false, String? instanceName, GetIt? getIt, + dynamic param1, + dynamic param2, }) { assert(_activeWatchItState != null, 'registerHandler can only be called inside a build function within a WatchingWidget or a widget using the WatchItMixin'); final getItInstance = getIt ?? di; - final parentObject = target ?? getItInstance(instanceName: instanceName); + final parentObject = target ?? + getItInstance( + instanceName: instanceName, param1: param1, param2: param2); _activeWatchItState!.watchListenable( parentOrListenable: parentObject, @@ -416,12 +439,16 @@ void registerStreamHandler({ T? target, String? instanceName, GetIt? getIt, + dynamic param1, + dynamic param2, }) { assert(_activeWatchItState != null, 'registerStreamHandler can only be called inside a build function within a WatchingWidget or a widget using the WatchItMixin'); final getItInstance = getIt ?? di; - final parentObject = target ?? getItInstance(instanceName: instanceName); + final parentObject = target ?? + getItInstance( + instanceName: instanceName, param1: param1, param2: param2); // Validate target type when no select function is provided if (select == null && parentObject is! Stream) { @@ -473,12 +500,16 @@ void registerFutureHandler({ bool callHandlerOnlyOnce = false, bool allowFutureChange = false, GetIt? getIt, + dynamic param1, + dynamic param2, }) { assert(_activeWatchItState != null, 'registerFutureHandler can only be called inside a build function within a WatchingWidget or a widget using the WatchItMixin'); final getItInstance = getIt ?? di; - final parentObject = target ?? getItInstance(instanceName: instanceName); + final parentObject = target ?? + getItInstance( + instanceName: instanceName, param1: param1, param2: param2); // Validate target type when no select function is provided if (select == null && parentObject is! Future) {