Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions lib/src/watch_it.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,14 @@ R watchValue<T extends Object, R>(
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<T>(instanceName: instanceName);
final parentObject = getItInstance<T>(
instanceName: instanceName, param1: param1, param2: param2);
final observedObject = _activeWatchItState!.watchListenable<T, R>(
parentOrListenable: parentObject,
selector: selectProperty,
Expand Down Expand Up @@ -171,13 +174,17 @@ R watchPropertyValue<T extends Listenable, R>(
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<T>(instanceName: instanceName);
final parentObject = target ??
getItInstance<T>(
instanceName: instanceName, param1: param1, param2: param2);
final R observedProperty = selectProperty(parentObject);
assert(
(observedProperty != null && observedProperty is! Listenable) ||
Expand Down Expand Up @@ -219,12 +226,16 @@ AsyncSnapshot<R> watchStream<T extends Object, R>(
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<T>(instanceName: instanceName);
final parentObject = target ??
getItInstance<T>(
instanceName: instanceName, param1: param1, param2: param2);

// Validate target type when no select function is provided
if (select == null && parentObject is! Stream<R>) {
Expand Down Expand Up @@ -271,12 +282,16 @@ AsyncSnapshot<R> watchFuture<T extends Object, R>(
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<T>(instanceName: instanceName);
final parentObject = target ??
getItInstance<T>(
instanceName: instanceName, param1: param1, param2: param2);

// Validate target type when no select function is provided
if (select == null && parentObject is! Future<R>) {
Expand Down Expand Up @@ -330,12 +345,16 @@ void registerHandler<T extends Object, R>({
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<T>(instanceName: instanceName);
final parentObject = target ??
getItInstance<T>(
instanceName: instanceName, param1: param1, param2: param2);

// Validate target type when no select function is provided
if (select == null && parentObject is! Listenable) {
Expand Down Expand Up @@ -375,12 +394,16 @@ void registerChangeNotifierHandler<T extends ChangeNotifier>({
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<T>(instanceName: instanceName);
final parentObject = target ??
getItInstance<T>(
instanceName: instanceName, param1: param1, param2: param2);

_activeWatchItState!.watchListenable<T, T>(
parentOrListenable: parentObject,
Expand Down Expand Up @@ -416,12 +439,16 @@ void registerStreamHandler<T extends Object, R>({
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<T>(instanceName: instanceName);
final parentObject = target ??
getItInstance<T>(
instanceName: instanceName, param1: param1, param2: param2);

// Validate target type when no select function is provided
if (select == null && parentObject is! Stream<R>) {
Expand Down Expand Up @@ -473,12 +500,16 @@ void registerFutureHandler<T extends Object, R>({
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<T>(instanceName: instanceName);
final parentObject = target ??
getItInstance<T>(
instanceName: instanceName, param1: param1, param2: param2);

// Validate target type when no select function is provided
if (select == null && parentObject is! Future<R>) {
Expand Down
Loading