when method Null safety

  1. @protected
Future<Object> when(
  1. bool predicate(
    1. Object action
    ),
  2. {Cubix? cubix}
)

this method returns a future object that is completed when the dispatching action is satisfied the given predicate

Implementation

@protected
Future<Object> when(bool Function(Object action) predicate, {Cubix? cubix}) {
  final completer = Completer<Object>();
  cubix ??= this.cubix;
  VoidCallback? removeListener;
  removeListener = cubix.when((action) {
    if (predicate(action)) {
      removeListener?.call();
      completer.complete(action);
    }
  });
  dispatcher.on(dispose: removeListener);
  return completer.future;
}