when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- int id,
- @JsonKey.new(name: 'commercial_id') int commercialId,
- @JsonKey.new(name: 'isibook_space_id') int isibookSpaceId,
- @JsonKey.new(name: 'start_date') @TimestampConverter() Jiffy startDate,
- int duration,
- @JsonKey.new(name: 'payment_online') bool paymentOnline,
- @JsonKey.new(name: 'payment_in_loco') bool paymentInLoco,
- @JsonKey.new(name: 'note_slot') String? noteSlot,
- String color,
- @JsonKey.new(name: 'deleted_at') @TimestampConverter() Jiffy? deletedAt,
- @JsonKey.new(name: 'created_at') @TimestampConverter() Jiffy createdAt,
- @JsonKey.new(name: 'updated_at') @TimestampConverter() Jiffy updatedAt,
- @JsonKey.new(name: 'isibook_space_reservation_id') int? isibookSpaceReservationId,
- @JsonKey.new(name: 'isibook_space_activity_id') int? isibookSpaceActivityId,
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,
@JsonKey(name: 'isibook_space_id') int isibookSpaceId,
@JsonKey(name: 'start_date') @TimestampConverter() Jiffy startDate,
int duration,
@JsonKey(name: 'payment_online') bool paymentOnline,
@JsonKey(name: 'payment_in_loco') bool paymentInLoco,
@JsonKey(name: 'note_slot') String? noteSlot,
String color,
@JsonKey(name: 'deleted_at') @TimestampConverter() Jiffy? deletedAt,
@JsonKey(name: 'created_at') @TimestampConverter() Jiffy createdAt,
@JsonKey(name: 'updated_at') @TimestampConverter() Jiffy updatedAt,
@JsonKey(name: 'isibook_space_reservation_id')
int? isibookSpaceReservationId,
@JsonKey(name: 'isibook_space_activity_id')
int? isibookSpaceActivityId)
$default,
) {
final _that = this;
switch (_that) {
case _IsibookReservationSlot():
return $default(
_that.id,
_that.commercialId,
_that.isibookSpaceId,
_that.startDate,
_that.duration,
_that.paymentOnline,
_that.paymentInLoco,
_that.noteSlot,
_that.color,
_that.deletedAt,
_that.createdAt,
_that.updatedAt,
_that.isibookSpaceReservationId,
_that.isibookSpaceActivityId);
}
}