whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<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 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( 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() when $default != null:
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 _:
  return null;

}
}