whenOrNull<TResult extends Object?> method
TResult?
whenOrNull<TResult extends Object?>({})
A variant of when
that fallback to returning null
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case _:
return null;
}
Implementation
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult? Function()? never,TResult? Function( int data)? timeout,TResult? Function( int data)? timestamp,}) {final _that = this;
switch (_that) {
case ExpirationNever() when never != null:
return never();case ExpirationTimeout() when timeout != null:
return timeout(_that.data);case ExpirationTimestamp() when timestamp != null:
return timestamp(_that.data);case _:
return null;
}
}