whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. bool? fetch,
    2. bool? console,
    3. bool? buffer,
    4. bool? stringDecoder,
    5. bool? timers,
    6. bool? stream,
    7. bool? crypto,
    8. bool? abort,
    9. bool? url,
    10. bool? events,
    11. bool? json,
    )?
)

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(
          bool? fetch,
          bool? console,
          bool? buffer,
          bool? stringDecoder,
          bool? timers,
          bool? stream,
          bool? crypto,
          bool? abort,
          bool? url,
          bool? events,
          bool? json)?
      $default,
) {
  final _that = this;
  switch (_that) {
    case _JsBuiltinOptions() when $default != null:
      return $default(
          _that.fetch,
          _that.console,
          _that.buffer,
          _that.stringDecoder,
          _that.timers,
          _that.stream,
          _that.crypto,
          _that.abort,
          _that.url,
          _that.events,
          _that.json);
    case _:
      return null;
  }
}