when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. num amount,
    3. String created,
    4. String currency,
    5. PaymentIntentsStatus status,
    6. String clientSecret,
    7. bool livemode,
    8. CaptureMethod captureMethod,
    9. ConfirmationMethod confirmationMethod,
    10. String? paymentMethodId,
    11. String? description,
    12. String? receiptEmail,
    13. String? canceledAt,
    14. NextAction? nextAction,
    15. ShippingDetails? shipping,
    16. MandateData? mandateData,
    17. String? latestCharge,
    )
)

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 id,  num amount,  String created,  String currency,  PaymentIntentsStatus status,  String clientSecret,  bool livemode,  CaptureMethod captureMethod,  ConfirmationMethod confirmationMethod,  String? paymentMethodId,  String? description,  String? receiptEmail,  String? canceledAt,  NextAction? nextAction,  ShippingDetails? shipping,  MandateData? mandateData,  String? latestCharge)  $default,) {final _that = this;
switch (_that) {
case _PaymentIntent():
return $default(_that.id,_that.amount,_that.created,_that.currency,_that.status,_that.clientSecret,_that.livemode,_that.captureMethod,_that.confirmationMethod,_that.paymentMethodId,_that.description,_that.receiptEmail,_that.canceledAt,_that.nextAction,_that.shipping,_that.mandateData,_that.latestCharge);case _:
  throw StateError('Unexpected subclass');

}
}