whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. int? ttl,
    2. int? tag,
    3. int? correlationId,
    4. Map<String, dynamic>? tvf,
    5. String? publishMethod,
    )?
)

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( int? ttl,  int? tag,  int? correlationId,  Map<String, dynamic>? tvf,  String? publishMethod)?  $default,) {final _that = this;
switch (_that) {
case _PublishOptions() when $default != null:
return $default(_that.ttl,_that.tag,_that.correlationId,_that.tvf,_that.publishMethod);case _:
  return null;

}
}