when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. @JsonKey.new(defaultValue: '') String email,
    3. String currencyCode,
    4. @JsonKey.new(defaultValue: '') String customerUrl,
    5. LineItemsOrder lineItems,
    6. String name,
    7. int orderNumber,
    8. String processedAt,
    9. ShippingAddress? shippingAddress,
    10. ShippingAddress? billingAddress,
    11. String statusUrl,
    12. @JsonKey.new(fromJson: _priceOrZero) PriceV2 subtotalPrice,
    13. PriceV2 totalPrice,
    14. PriceV2 totalShippingPrice,
    15. @JsonKey.new(fromJson: _priceOrZero) PriceV2 totalTax,
    16. @JsonKey.new(defaultValue: '') String financialStatus,
    17. String fulfillmentStatus,
    18. PriceV2? totalRefunded,
    19. String? phone,
    20. String? cursor,
    21. String? canceledAt,
    22. String? cancelReason,
    23. List<SuccessfulFullfilment>? successfulFulfillments,
    )
)

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, @JsonKey(defaultValue: '')  String email,  String currencyCode, @JsonKey(defaultValue: '')  String customerUrl,  LineItemsOrder lineItems,  String name,  int orderNumber,  String processedAt,  ShippingAddress? shippingAddress,  ShippingAddress? billingAddress,  String statusUrl, @JsonKey(fromJson: _priceOrZero)  PriceV2 subtotalPrice,  PriceV2 totalPrice,  PriceV2 totalShippingPrice, @JsonKey(fromJson: _priceOrZero)  PriceV2 totalTax, @JsonKey(defaultValue: '')  String financialStatus,  String fulfillmentStatus,  PriceV2? totalRefunded,  String? phone,  String? cursor,  String? canceledAt,  String? cancelReason,  List<SuccessfulFullfilment>? successfulFulfillments)  $default,) {final _that = this;
switch (_that) {
case _Order():
return $default(_that.id,_that.email,_that.currencyCode,_that.customerUrl,_that.lineItems,_that.name,_that.orderNumber,_that.processedAt,_that.shippingAddress,_that.billingAddress,_that.statusUrl,_that.subtotalPrice,_that.totalPrice,_that.totalShippingPrice,_that.totalTax,_that.financialStatus,_that.fulfillmentStatus,_that.totalRefunded,_that.phone,_that.cursor,_that.canceledAt,_that.cancelReason,_that.successfulFulfillments);case _:
  throw StateError('Unexpected subclass');

}
}