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: 'account_id') int accountId,
    4. int points,
    5. Map<String, dynamic>? payment,
    6. bool pending,
    7. @JsonKey.new(name: 'created_at') @TimestampConverter() Jiffy createdAt,
    8. @JsonKey.new(name: 'updated_at') @TimestampConverter() Jiffy updatedAt,
    9. String description,
    )
)

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: 'account_id') int accountId,
          int points,
          Map<String, dynamic>? payment,
          bool pending,
          @JsonKey(name: 'created_at') @TimestampConverter() Jiffy createdAt,
          @JsonKey(name: 'updated_at') @TimestampConverter() Jiffy updatedAt,
          String description)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _IsibookPointsLog():
      return $default(
          _that.id,
          _that.commercialId,
          _that.accountId,
          _that.points,
          _that.payment,
          _that.pending,
          _that.createdAt,
          _that.updatedAt,
          _that.description);
  }
}