when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. PaymentElementShowTerms? applePay,
    2. PaymentElementShowTerms? auBecsDebit,
    3. PaymentElementShowTerms? bancontact,
    4. PaymentElementShowTerms? card,
    5. PaymentElementShowTerms? cashApp,
    6. PaymentElementShowTerms? googlePay,
    7. PaymentElementShowTerms? ideal,
    8. PaymentElementShowTerms? payPal,
    9. PaymentElementShowTerms? sepaDebit,
    10. PaymentElementShowTerms? sofort,
    11. PaymentElementShowTerms? usBankAccount,
    )
)

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( PaymentElementShowTerms? applePay,  PaymentElementShowTerms? auBecsDebit,  PaymentElementShowTerms? bancontact,  PaymentElementShowTerms? card,  PaymentElementShowTerms? cashApp,  PaymentElementShowTerms? googlePay,  PaymentElementShowTerms? ideal,  PaymentElementShowTerms? payPal,  PaymentElementShowTerms? sepaDebit,  PaymentElementShowTerms? sofort,  PaymentElementShowTerms? usBankAccount)  $default,) {final _that = this;
switch (_that) {
case _PaymentElementOptionsTerms():
return $default(_that.applePay,_that.auBecsDebit,_that.bancontact,_that.card,_that.cashApp,_that.googlePay,_that.ideal,_that.payPal,_that.sepaDebit,_that.sofort,_that.usBankAccount);case _:
  throw StateError('Unexpected subclass');

}
}