when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- String? cartId,
- String? intent,
- PPBillingType? billingType,
- String? paymentId,
- String? billingToken,
- List<
PPItem> ? items, - CartAmounts? amounts,
- String? description,
- @JsonKey.new(name: 'cancelUrl', readValue: _PPCartHelper.readUrl) String? cancelUrl,
- @JsonKey.new(name: 'returnUrl', readValue: _PPCartHelper.readUrl) String? returnUrl,
- PPAmount? total,
- List<
PPShippingMethods> ? shippingMethods, - PPCartAddress? shippingAddress,
- PPCartAddress? billingAddress,
- PPAmount? totalAllowedOverCaptureAmount,
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? cartId,
String? intent,
PPBillingType? billingType,
String? paymentId,
String? billingToken,
List<PPItem>? items,
CartAmounts? amounts,
String? description,
@JsonKey(name: 'cancelUrl', readValue: _PPCartHelper.readUrl)
String? cancelUrl,
@JsonKey(name: 'returnUrl', readValue: _PPCartHelper.readUrl)
String? returnUrl,
PPAmount? total,
List<PPShippingMethods>? shippingMethods,
PPCartAddress? shippingAddress,
PPCartAddress? billingAddress,
PPAmount? totalAllowedOverCaptureAmount)
$default,
) {
final _that = this;
switch (_that) {
case _PPCart():
return $default(
_that.cartId,
_that.intent,
_that.billingType,
_that.paymentId,
_that.billingToken,
_that.items,
_that.amounts,
_that.description,
_that.cancelUrl,
_that.returnUrl,
_that.total,
_that.shippingMethods,
_that.shippingAddress,
_that.billingAddress,
_that.totalAllowedOverCaptureAmount);
case _:
throw StateError('Unexpected subclass');
}
}