maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
  1. TResult $default(
    1. int id,
    2. @JsonKey.new(name: 'commercial_id') int commercialId,
    3. String name,
    4. String? description,
    5. @JsonKey.new(name: 'max_people') int maxPeople,
    6. @JsonKey.new(name: 'slot_interval') int slotInterval,
    7. @JsonKey.new(name: 'interval_price') List<IsibookIntervalPrice> intervalPrice,
    8. List images,
    9. @JsonKey.new(name: 'meta_value') List metaValue,
    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. List tags,
    14. @JsonKey.new(name: 'min_number_slot_reserved') int minNumberSlotReserved,
    15. @JsonKey.new(name: 'max_number_slot_reserved') int maxNumberSlotReserved,
    16. @JsonKey.new(name: 'spaces') List<int> spaces,
    17. @JsonKey.new(name: 'order_column') int orderColumn,
    18. List<int> extras,
    19. @JsonKey.new(name: 'can_pay_with_points') bool canPayWithPoints,
    20. @JsonKey.new(name: 'is_discount_active') bool isDiscountActive,
    21. String? color,
    22. @JsonKey.new(name: 'images_url') List imagesUrl,
    23. @JsonKey.new(name: 'isibook_space_time_slots') List<IsibookSpaceTimeSlot> timeSlots,
    )?, {
  2. required TResult orElse(),
})

A variant of when that fallback to an orElse callback.

It is equivalent to doing:

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

Implementation

@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
  TResult Function(
          int id,
          @JsonKey(name: 'commercial_id') int commercialId,
          String name,
          String? description,
          @JsonKey(name: 'max_people') int maxPeople,
          @JsonKey(name: 'slot_interval') int slotInterval,
          @JsonKey(name: 'interval_price')
          List<IsibookIntervalPrice> intervalPrice,
          List<dynamic> images,
          @JsonKey(name: 'meta_value') List<dynamic> metaValue,
          @JsonKey(name: 'deleted_at') @TimestampConverter() Jiffy? deletedAt,
          @JsonKey(name: 'created_at') @TimestampConverter() Jiffy createdAt,
          @JsonKey(name: 'updated_at') @TimestampConverter() Jiffy updatedAt,
          List<dynamic> tags,
          @JsonKey(name: 'min_number_slot_reserved')
          int minNumberSlotReserved,
          @JsonKey(name: 'max_number_slot_reserved')
          int maxNumberSlotReserved,
          @JsonKey(name: 'spaces') List<int> spaces,
          @JsonKey(name: 'order_column') int orderColumn,
          List<int> extras,
          @JsonKey(name: 'can_pay_with_points') bool canPayWithPoints,
          @JsonKey(name: 'is_discount_active') bool isDiscountActive,
          String? color,
          @JsonKey(name: 'images_url') List<dynamic> imagesUrl,
          @JsonKey(name: 'isibook_space_time_slots')
          List<IsibookSpaceTimeSlot> timeSlots)?
      $default, {
  required TResult orElse(),
}) {
  final _that = this;
  switch (_that) {
    case _IsibookSpace() when $default != null:
      return $default(
          _that.id,
          _that.commercialId,
          _that.name,
          _that.description,
          _that.maxPeople,
          _that.slotInterval,
          _that.intervalPrice,
          _that.images,
          _that.metaValue,
          _that.deletedAt,
          _that.createdAt,
          _that.updatedAt,
          _that.tags,
          _that.minNumberSlotReserved,
          _that.maxNumberSlotReserved,
          _that.spaces,
          _that.orderColumn,
          _that.extras,
          _that.canPayWithPoints,
          _that.isDiscountActive,
          _that.color,
          _that.imagesUrl,
          _that.timeSlots);
    case _:
      return orElse();
  }
}