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: '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 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: '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() when $default != null:
      return $default(
          _that.id,
          _that.commercialId,
          _that.accountId,
          _that.points,
          _that.payment,
          _that.pending,
          _that.createdAt,
          _that.updatedAt,
          _that.description);
    case _:
      return null;
  }
}