when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- String? referenceId,
- String? invoiceId,
- String? customId,
- String? softDescriptor,
- PPShipping? shipping,
- List<
PPItems> ? items, - PPPayee? payee,
- @JsonKey.new(name: 'amount') PPOrderAmount orderAmount,
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? referenceId,
String? invoiceId,
String? customId,
String? softDescriptor,
PPShipping? shipping,
List<PPItems>? items,
PPPayee? payee,
@JsonKey(name: 'amount') PPOrderAmount orderAmount)
$default,
) {
final _that = this;
switch (_that) {
case _PPPurchaseUnit():
return $default(
_that.referenceId,
_that.invoiceId,
_that.customId,
_that.softDescriptor,
_that.shipping,
_that.items,
_that.payee,
_that.orderAmount);
case _:
throw StateError('Unexpected subclass');
}
}