maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. String? checkoutUrl,
    3. CartCost? cost,
    4. int? totalQuantity,
    5. List<CartDiscountAllocation?>? discountAllocations,
    6. List<CartDiscountCode?>? discountCodes,
    7. String? createdAt,
    8. List<Attribute?>? attributes,
    9. CartBuyerIdentity? buyerIdentity,
    10. String? note,
    11. String? updatedAt,
    12. List<Line> lines,
    )?, {
  2. required TResult orElse(),
})

A variant of when that fallback to an orElse callback.

It is equivalent to doing:

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

Implementation

@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String id,  String? checkoutUrl,  CartCost? cost,  int? totalQuantity,  List<CartDiscountAllocation?>? discountAllocations,  List<CartDiscountCode?>? discountCodes,  String? createdAt,  List<Attribute?>? attributes,  CartBuyerIdentity? buyerIdentity,  String? note,  String? updatedAt, @JsonKey(fromJson: JsonHelper.lines)  List<Line> lines)?  $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _Cart() when $default != null:
return $default(_that.id,_that.checkoutUrl,_that.cost,_that.totalQuantity,_that.discountAllocations,_that.discountCodes,_that.createdAt,_that.attributes,_that.buyerIdentity,_that.note,_that.updatedAt,_that.lines);case _:
  return orElse();

}
}