maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
  1. TResult $default(
    1. int id,
    2. @JsonKey.new(name: 'commercial_local_id') String commercialLocalId,
    3. String name,
    4. @JsonKey.new(name: 'description_discount') String? descriptionDiscount,
    5. num price,
    6. int points,
    7. String? note,
    8. @JsonKey.new(name: 'created_at') @TimestampConverter() Jiffy? createdAt,
    9. @JsonKey.new(name: 'updated_at') @TimestampConverter() Jiffy? updatedAt,
    )?, {
  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_local_id') String commercialLocalId,
          String name,
          @JsonKey(name: 'description_discount') String? descriptionDiscount,
          num price,
          int points,
          String? note,
          @JsonKey(name: 'created_at') @TimestampConverter() Jiffy? createdAt,
          @JsonKey(name: 'updated_at')
          @TimestampConverter()
          Jiffy? updatedAt)?
      $default, {
  required TResult orElse(),
}) {
  final _that = this;
  switch (_that) {
    case _CommercialPointPack() when $default != null:
      return $default(
          _that.id,
          _that.commercialLocalId,
          _that.name,
          _that.descriptionDiscount,
          _that.price,
          _that.points,
          _that.note,
          _that.createdAt,
          _that.updatedAt);
    case _:
      return orElse();
  }
}