when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- int id,
- @JsonKey.new(name: 'commercial_id') int commercialId,
- String name,
- String description,
- List<
String> images, - @JsonKey.new(name: 'min_number_slot_reserved') int minNumberSlotReserved,
- @JsonKey.new(name: 'max_number_slot_reserved') int maxNumberSlotReserved,
- List<
IsibookExtraPrice> price, - @JsonKey.new(name: 'created_at') @TimestampConverter() Jiffy createdAt,
- @JsonKey.new(name: 'updated_at') @TimestampConverter() Jiffy updatedAt,
- @JsonKey.new(name: 'deleted_at') @TimestampConverter() Jiffy? deletedAt,
- @JsonKey.new(name: 'images_url') List<
String> imagesUrl,
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_id') int commercialId,
String name,
String description,
List<String> images,
@JsonKey(name: 'min_number_slot_reserved')
int minNumberSlotReserved,
@JsonKey(name: 'max_number_slot_reserved')
int maxNumberSlotReserved,
List<IsibookExtraPrice> price,
@JsonKey(name: 'created_at') @TimestampConverter() Jiffy createdAt,
@JsonKey(name: 'updated_at') @TimestampConverter() Jiffy updatedAt,
@JsonKey(name: 'deleted_at') @TimestampConverter() Jiffy? deletedAt,
@JsonKey(name: 'images_url') List<String> imagesUrl)
$default,
) {
final _that = this;
switch (_that) {
case _IsibookReservationExtra():
return $default(
_that.id,
_that.commercialId,
_that.name,
_that.description,
_that.images,
_that.minNumberSlotReserved,
_that.maxNumberSlotReserved,
_that.price,
_that.createdAt,
_that.updatedAt,
_that.deletedAt,
_that.imagesUrl);
}
}