whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String id,
    2. bool ready,
    3. AvailableShippingRates? availableShippingRates,
    4. String createdAt,
    5. String currencyCode,
    6. PriceV2 totalTaxV2,
    7. PriceV2 totalPriceV2,
    8. bool taxesIncluded,
    9. bool taxExempt,
    10. PriceV2 subtotalPriceV2,
    11. bool requiresShipping,
    12. List<AppliedGiftCards> appliedGiftCards,
    13. List<LineItem> lineItems,
    14. Order? order,
    15. String? orderStatusUrl,
    16. String? shopifyPaymentsAccountId,
    17. MailingAddress? shippingAddress,
    18. ShippingRates? shippingLine,
    19. String? email,
    20. String? completedAt,
    21. String? note,
    22. String? webUrl,
    23. String? updatedAt,
    )?
)

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,  bool ready,  AvailableShippingRates? availableShippingRates,  String createdAt,  String currencyCode,  PriceV2 totalTaxV2,  PriceV2 totalPriceV2,  bool taxesIncluded,  bool taxExempt,  PriceV2 subtotalPriceV2,  bool requiresShipping,  List<AppliedGiftCards> appliedGiftCards, @JsonKey(fromJson: JsonHelper.lineItems)  List<LineItem> lineItems,  Order? order,  String? orderStatusUrl,  String? shopifyPaymentsAccountId,  MailingAddress? shippingAddress,  ShippingRates? shippingLine,  String? email,  String? completedAt,  String? note,  String? webUrl,  String? updatedAt)?  $default,) {final _that = this;
switch (_that) {
case _Checkout() when $default != null:
return $default(_that.id,_that.ready,_that.availableShippingRates,_that.createdAt,_that.currencyCode,_that.totalTaxV2,_that.totalPriceV2,_that.taxesIncluded,_that.taxExempt,_that.subtotalPriceV2,_that.requiresShipping,_that.appliedGiftCards,_that.lineItems,_that.order,_that.orderStatusUrl,_that.shopifyPaymentsAccountId,_that.shippingAddress,_that.shippingLine,_that.email,_that.completedAt,_that.note,_that.webUrl,_that.updatedAt);case _:
  return null;

}
}