when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String $type,
    2. String source,
    3. int id,
    4. @JsonKey.new(toJson: iso8601) DateTime createdAt,
    5. String createdBy,
    6. String type,
    7. String? subject,
    8. int? reportId,
    9. int? actionEventId,
    10. @ModEventViewConverter() ModEventView? event,
    11. @ReportActivityViewConverter() ReportActivityView? activity,
    12. Map<String, dynamic>? $unknown,
    )
)

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( String $type,  String source,  int id, @JsonKey(toJson: iso8601)  DateTime createdAt,  String createdBy,  String type,  String? subject,  int? reportId,  int? actionEventId, @ModEventViewConverter()  ModEventView? event, @ReportActivityViewConverter()  ReportActivityView? activity,  Map<String, dynamic>? $unknown)  $default,) {final _that = this;
switch (_that) {
case _ActivityRow():
return $default(_that.$type,_that.source,_that.id,_that.createdAt,_that.createdBy,_that.type,_that.subject,_that.reportId,_that.actionEventId,_that.event,_that.activity,_that.$unknown);case _:
  throw StateError('Unexpected subclass');

}
}