when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String id,
- String object,
- BillingDetails? billingDetails,
- String? customer,
- Map<
String, dynamic> metadata, - bool livemode,
- int? created,
- CardPaymentMethod? card,
- SepaDebit? sepaDebit,
- BacsDebit? bacsDebit,
- AuBecsDebit? auBecsDebit,
- Ideal? ideal,
- Fpx? fpx,
- Upi? upi,
- UsBankAccount? usBankAccount,
- PaymentMethodType type,
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, String object, BillingDetails? billingDetails, String? customer, Map<String, dynamic> metadata, bool livemode, int? created, CardPaymentMethod? card, SepaDebit? sepaDebit, BacsDebit? bacsDebit, AuBecsDebit? auBecsDebit, Ideal? ideal, Fpx? fpx, Upi? upi, UsBankAccount? usBankAccount, PaymentMethodType type) $default,) {final _that = this;
switch (_that) {
case _PaymentMethod():
return $default(_that.id,_that.object,_that.billingDetails,_that.customer,_that.metadata,_that.livemode,_that.created,_that.card,_that.sepaDebit,_that.bacsDebit,_that.auBecsDebit,_that.ideal,_that.fpx,_that.upi,_that.usBankAccount,_that.type);case _:
throw StateError('Unexpected subclass');
}
}