when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. int id,
    2. @JsonKey.new(name: 'commercial_id') int commercialId,
    3. @JsonKey.new(name: 'isibook_spaces_id') int isibookSpacesId,
    4. List<int> extras,
    5. @JsonKey.new(name: 'payment_type') IsibookPaymentType paymentType,
    6. @JsonKey.new(name: 'electronic_confirmed') dynamic electronicConfirmed,
    7. @JsonKey.new(name: 'amount_payed') num amountPayed,
    8. int customers,
    9. @JsonKey.new(name: 'reservation_id') int reservationId,
    10. @JsonKey.new(name: 'account_id') int accountId,
    11. @JsonKey.new(name: 'account_temp') dynamic accountTemp,
    12. @JsonKey.new(name: 'created_at') @TimestampConverter() Jiffy createdAt,
    13. @JsonKey.new(name: 'updated_at') @TimestampConverter() Jiffy updatedAt,
    14. @JsonKey.new(name: 'datetime_first_slot') @TimestampConverter() Jiffy datetimeFirstSlot,
    15. @JsonKey.new(name: 'datetime_last_slot') @TimestampConverter() Jiffy datetimeLastSlot,
    16. @JsonKey.new(name: 'cancel_at') @TimestampConverter() Jiffy? cancelAt,
    17. @JsonKey.new(name: 'cancel_by') String? cancelBy,
    18. @JsonKey.new(name: 'isibook_space_activity_id') int? isibookSpaceActivityId,
    19. @JsonKey.new(name: 'isibook_space_activity_connected_id') int? isibookSpaceActivityConnectedId,
    20. @JsonKey.new(name: 'recover_code_fattura') String? recoverCodeFattura,
    21. @JsonKey.new(name: 'error_fattura') String? errorFattura,
    22. @JsonKey.new(name: 'need_fattura') bool needFattura,
    23. @JsonKey.new(name: 'backoffice') bool backoffice,
    24. String? note,
    )
)

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_spaces_id') int isibookSpacesId,
          List<int> extras,
          @JsonKey(name: 'payment_type') IsibookPaymentType paymentType,
          @JsonKey(name: 'electronic_confirmed') dynamic electronicConfirmed,
          @JsonKey(name: 'amount_payed') num amountPayed,
          int customers,
          @JsonKey(name: 'reservation_id') int reservationId,
          @JsonKey(name: 'account_id') int accountId,
          @JsonKey(name: 'account_temp') dynamic accountTemp,
          @JsonKey(name: 'created_at') @TimestampConverter() Jiffy createdAt,
          @JsonKey(name: 'updated_at') @TimestampConverter() Jiffy updatedAt,
          @JsonKey(name: 'datetime_first_slot')
          @TimestampConverter()
          Jiffy datetimeFirstSlot,
          @JsonKey(name: 'datetime_last_slot')
          @TimestampConverter()
          Jiffy datetimeLastSlot,
          @JsonKey(name: 'cancel_at') @TimestampConverter() Jiffy? cancelAt,
          @JsonKey(name: 'cancel_by') String? cancelBy,
          @JsonKey(name: 'isibook_space_activity_id')
          int? isibookSpaceActivityId,
          @JsonKey(name: 'isibook_space_activity_connected_id')
          int? isibookSpaceActivityConnectedId,
          @JsonKey(name: 'recover_code_fattura') String? recoverCodeFattura,
          @JsonKey(name: 'error_fattura') String? errorFattura,
          @JsonKey(name: 'need_fattura') bool needFattura,
          @JsonKey(name: 'backoffice') bool backoffice,
          String? note)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _IsibookReservation():
      return $default(
          _that.id,
          _that.commercialId,
          _that.isibookSpacesId,
          _that.extras,
          _that.paymentType,
          _that.electronicConfirmed,
          _that.amountPayed,
          _that.customers,
          _that.reservationId,
          _that.accountId,
          _that.accountTemp,
          _that.createdAt,
          _that.updatedAt,
          _that.datetimeFirstSlot,
          _that.datetimeLastSlot,
          _that.cancelAt,
          _that.cancelBy,
          _that.isibookSpaceActivityId,
          _that.isibookSpaceActivityConnectedId,
          _that.recoverCodeFattura,
          _that.errorFattura,
          _that.needFattura,
          _that.backoffice,
          _that.note);
  }
}