whenAsync method
Async-aware version of ObjectExtension.when.
Returns this FutureOr<T> if condition evaluates to true, otherwise null.
condition can be:
boolbool Function()(lazy)- anything else →
false
Implementation
FutureOr<T?> whenAsync(Object? condition) {
final self = this;
if (self is Future<T>) {
return self.then((val) => _evalCondition(condition) ? val : null);
} else {
return _evalCondition(condition) ? self : null;
}
}