when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String $type,
- int id,
- int eventId,
- @ReportViewStatusConverter() ReportViewStatus status,
- @SubjectViewConverter() SubjectView subject,
- @ReasonTypeConverter() ReasonType reportType,
- String reportedBy,
- @SubjectViewConverter() SubjectView reporter,
- String? comment,
- DateTime createdAt,
- DateTime? updatedAt,
- DateTime? queuedAt,
- List<
int> ? actionEventIds, - @ModEventViewConverter() List<
ModEventView> ? actions, - String? actionNote,
- @SubjectStatusViewConverter() SubjectStatusView? subjectStatus,
- @ReportAssignmentConverter() ReportAssignment? assignment,
- @QueueViewConverter() QueueView? queue,
- bool? isMuted,
- 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, int id, int eventId, @ReportViewStatusConverter() ReportViewStatus status, @SubjectViewConverter() SubjectView subject, @ReasonTypeConverter() ReasonType reportType, String reportedBy, @SubjectViewConverter() SubjectView reporter, String? comment, DateTime createdAt, DateTime? updatedAt, DateTime? queuedAt, List<int>? actionEventIds, @ModEventViewConverter() List<ModEventView>? actions, String? actionNote, @SubjectStatusViewConverter() SubjectStatusView? subjectStatus, int? relatedReportCount, @ReportAssignmentConverter() ReportAssignment? assignment, @QueueViewConverter() QueueView? queue, bool? isMuted, Map<String, dynamic>? $unknown) $default,) {final _that = this;
switch (_that) {
case _ReportView():
return $default(_that.$type,_that.id,_that.eventId,_that.status,_that.subject,_that.reportType,_that.reportedBy,_that.reporter,_that.comment,_that.createdAt,_that.updatedAt,_that.queuedAt,_that.actionEventIds,_that.actions,_that.actionNote,_that.subjectStatus,_that.relatedReportCount,_that.assignment,_that.queue,_that.isMuted,_that.$unknown);case _:
throw StateError('Unexpected subclass');
}
}