whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. List<HTTPAccount>? accounts,
    2. @JsonKey.new(name: 'allowTransparent') bool? transparent,
    3. int? userLevel
    )?
)

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( List<HTTPAccount>? accounts, @JsonKey(name: 'allowTransparent')  bool? transparent,  int? userLevel)?  $default,) {final _that = this;
switch (_that) {
case _HTTPServerConfig() when $default != null:
return $default(_that.accounts,_that.transparent,_that.userLevel);case _:
  return null;

}
}