whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String? referenceId,
    2. String? invoiceId,
    3. String? customId,
    4. String? softDescriptor,
    5. PPShipping? shipping,
    6. List<PPItems>? items,
    7. PPPayee? payee,
    8. @JsonKey.new(name: 'amount') PPOrderAmount orderAmount,
    )?
)

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(
          String? referenceId,
          String? invoiceId,
          String? customId,
          String? softDescriptor,
          PPShipping? shipping,
          List<PPItems>? items,
          PPPayee? payee,
          @JsonKey(name: 'amount') PPOrderAmount orderAmount)?
      $default,
) {
  final _that = this;
  switch (_that) {
    case _PPPurchaseUnit() when $default != null:
      return $default(
          _that.referenceId,
          _that.invoiceId,
          _that.customId,
          _that.softDescriptor,
          _that.shipping,
          _that.items,
          _that.payee,
          _that.orderAmount);
    case _:
      return null;
  }
}