whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. int id,
    2. String name,
    3. int suiteID,
    4. List<int> groupIDs,
    5. int? line,
    6. int? column,
    7. String? url,
    8. int? rootLine,
    9. int? rootColumn,
    10. String? rootUrl,
    11. TestMetadata metadata,
    )?
)

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 id,
          String name,
          int suiteID,
          List<int> groupIDs,
          int? line,
          int? column,
          String? url,
          int? rootLine,
          int? rootColumn,
          String? rootUrl,
          TestMetadata metadata)?
      $default,
) {
  final _that = this;
  switch (_that) {
    case _Test() when $default != null:
      return $default(
          _that.id,
          _that.name,
          _that.suiteID,
          _that.groupIDs,
          _that.line,
          _that.column,
          _that.url,
          _that.rootLine,
          _that.rootColumn,
          _that.rootUrl,
          _that.metadata);
    case _:
      return null;
  }
}