when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<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 switch-like method, using callbacks.

As opposed to map, this offers destructuring. It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case Subclass2(:final field2):
    return ...;
}

Implementation

@optionalTypeArgs
TResult when<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():
      return $default(
          _that.referenceId,
          _that.invoiceId,
          _that.customId,
          _that.softDescriptor,
          _that.shipping,
          _that.items,
          _that.payee,
          _that.orderAmount);
    case _:
      throw StateError('Unexpected subclass');
  }
}