when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. double amount,
    2. String label,
    3. DateTime? recurringPaymentStartDate,
    4. DateTime? recurringPaymentEndDate,
    5. ApplePayRecurringPaymentTimeInterVal? recurringPaymentIntervalUnit,
    6. int? recurringPaymentIntervalCount,
    )
)

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( double amount,  String label,  DateTime? recurringPaymentStartDate,  DateTime? recurringPaymentEndDate,  ApplePayRecurringPaymentTimeInterVal? recurringPaymentIntervalUnit,  int? recurringPaymentIntervalCount)  $default,) {final _that = this;
switch (_that) {
case _PaymentElementRecurringPaymentProperties():
return $default(_that.amount,_that.label,_that.recurringPaymentStartDate,_that.recurringPaymentEndDate,_that.recurringPaymentIntervalUnit,_that.recurringPaymentIntervalCount);case _:
  throw StateError('Unexpected subclass');

}
}