when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default()
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, 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,) {final _that = this;
switch (_that) {
case _Cart():
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 _:
throw StateError('Unexpected subclass');
}
}