when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String $type,
- String source,
- int id,
- @JsonKey.new(toJson: iso8601) DateTime createdAt,
- String createdBy,
- String type,
- String? subject,
- int? reportId,
- int? actionEventId,
- @ModEventViewConverter() ModEventView? event,
- @ReportActivityViewConverter() ReportActivityView? activity,
- 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');
}
}