when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- int id,
- @JsonKey.new(name: 'commercial_local_id') String commercialLocalId,
- String name,
- @JsonKey.new(name: 'description_discount') String? descriptionDiscount,
- num price,
- int points,
- String? note,
- @JsonKey.new(name: 'created_at') @TimestampConverter() Jiffy? createdAt,
- @JsonKey.new(name: 'updated_at') @TimestampConverter() Jiffy? updatedAt,
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(
int id,
@JsonKey(name: 'commercial_local_id') String commercialLocalId,
String name,
@JsonKey(name: 'description_discount') String? descriptionDiscount,
num price,
int points,
String? note,
@JsonKey(name: 'created_at') @TimestampConverter() Jiffy? createdAt,
@JsonKey(name: 'updated_at') @TimestampConverter() Jiffy? updatedAt)
$default,
) {
final _that = this;
switch (_that) {
case _CommercialPointPack():
return $default(
_that.id,
_that.commercialLocalId,
_that.name,
_that.descriptionDiscount,
_that.price,
_that.points,
_that.note,
_that.createdAt,
_that.updatedAt);
}
}