whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. int? plusOne,
    2. int? minusOne,
    3. int? confused,
    4. int? eyes,
    5. int? heart,
    6. int? hooray,
    7. int? laugh,
    8. int? rocket,
    9. int totalCount,
    10. ModelUri? url,
    )?
)

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? plusOne,
          int? minusOne,
          int? confused,
          int? eyes,
          int? heart,
          int? hooray,
          int? laugh,
          int? rocket,
          int totalCount,
          ModelUri? url)?
      $default,
) {
  final _that = this;
  switch (_that) {
    case _GithubReactionValue() when $default != null:
      return $default(
          _that.plusOne,
          _that.minusOne,
          _that.confused,
          _that.eyes,
          _that.heart,
          _that.hooray,
          _that.laugh,
          _that.rocket,
          _that.totalCount,
          _that.url);
    case _:
      return null;
  }
}