whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. int id,
    2. @JsonKey.new(name: 'commercial_id') int commercialId,
    3. @JsonKey.new(name: 'isibook_space_id') int isibookSpaceId,
    4. @JsonKey.new(name: 'start_date') @TimestampConverter() Jiffy startDate,
    5. int duration,
    6. @JsonKey.new(name: 'payment_online') bool paymentOnline,
    7. @JsonKey.new(name: 'payment_in_loco') bool paymentInLoco,
    8. @JsonKey.new(name: 'note_slot') String? noteSlot,
    9. String color,
    10. @JsonKey.new(name: 'deleted_at') @TimestampConverter() Jiffy? deletedAt,
    11. @JsonKey.new(name: 'created_at') @TimestampConverter() Jiffy createdAt,
    12. @JsonKey.new(name: 'updated_at') @TimestampConverter() Jiffy updatedAt,
    13. @JsonKey.new(name: 'isibook_space_reservation_id') int? isibookSpaceReservationId,
    14. @JsonKey.new(name: 'isibook_space_activity_id') int? isibookSpaceActivityId,
    )?
)

A variant of when that fallback to returning null

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return null;
}

Implementation

@optionalTypeArgs
TResult? whenOrNull<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() when $default != null:
      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);
    case _:
      return null;
  }
}