whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String id,
    2. String email,
    3. String currencyCode,
    4. String customerUrl,
    5. LineItemsOrder lineItems,
    6. String name,
    7. int orderNumber,
    8. String processedAt,
    9. ShippingAddress? shippingAddress,
    10. ShippingAddress? billingAddress,
    11. String statusUrl,
    12. PriceV2 subtotalPriceV2,
    13. PriceV2 totalPriceV2,
    14. PriceV2 totalShippingPriceV2,
    15. PriceV2 totalTaxV2,
    16. String financialStatus,
    17. String fulfillmentStatus,
    18. PriceV2? totalRefundedV2,
    19. String? phone,
    20. String? cursor,
    21. String? canceledAt,
    22. String? cancelReason,
    23. List<SuccessfulFullfilment>? successfulFulfillments,
    )?
)

A variant of when that fallback to returning null

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return null;
}

Implementation

@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String id,  String email,  String currencyCode,  String customerUrl,  LineItemsOrder lineItems,  String name,  int orderNumber,  String processedAt,  ShippingAddress? shippingAddress,  ShippingAddress? billingAddress,  String statusUrl,  PriceV2 subtotalPriceV2,  PriceV2 totalPriceV2,  PriceV2 totalShippingPriceV2,  PriceV2 totalTaxV2,  String financialStatus,  String fulfillmentStatus,  PriceV2? totalRefundedV2,  String? phone,  String? cursor,  String? canceledAt,  String? cancelReason,  List<SuccessfulFullfilment>? successfulFulfillments)?  $default,) {final _that = this;
switch (_that) {
case _Order() when $default != null:
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.subtotalPriceV2,_that.totalPriceV2,_that.totalShippingPriceV2,_that.totalTaxV2,_that.financialStatus,_that.fulfillmentStatus,_that.totalRefundedV2,_that.phone,_that.cursor,_that.canceledAt,_that.cancelReason,_that.successfulFulfillments);case _:
  return null;

}
}