when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String paymentDescription,
    2. String managementUrl,
    3. String? billingAgreement,
    4. DateTime? freeCancellationDate,
    5. String? freeCancellationTimezone,
    6. PaymentElementApplePayDeferredPaymentProperties deferredBilling,
    )
)

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 paymentDescription,  String managementUrl,  String? billingAgreement,  DateTime? freeCancellationDate,  String? freeCancellationTimezone,  PaymentElementApplePayDeferredPaymentProperties deferredBilling)  $default,) {final _that = this;
switch (_that) {
case _PaymentElementApplePayDeferredPaymentRequest():
return $default(_that.paymentDescription,_that.managementUrl,_that.billingAgreement,_that.freeCancellationDate,_that.freeCancellationTimezone,_that.deferredBilling);case _:
  throw StateError('Unexpected subclass');

}
}