when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String $type,
- int id,
- USubjectStatusViewSubject subject,
- USubjectStatusViewHosting? hosting,
- List<
String> ? subjectBlobCids, - String? subjectRepoHandle,
- DateTime updatedAt,
- DateTime createdAt,
- SubjectReviewState reviewState,
- String? comment,
- int? priorityScore,
- DateTime? muteUntil,
- DateTime? muteReportingUntil,
- String? lastReviewedBy,
- DateTime? lastReviewedAt,
- DateTime? lastReportedAt,
- DateTime? lastAppealedAt,
- bool? takendown,
- bool? appealed,
- DateTime? suspendUntil,
- List<
String> ? tags, - AccountStats? accountStats,
- RecordsStats? recordsStats,
- SubjectStatusViewAgeAssuranceState? ageAssuranceState,
- SubjectStatusViewAgeAssuranceUpdatedBy? ageAssuranceUpdatedBy,
- 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, @USubjectStatusViewSubjectConverter() USubjectStatusViewSubject subject, @USubjectStatusViewHostingConverter() USubjectStatusViewHosting? hosting, List<String>? subjectBlobCids, String? subjectRepoHandle, DateTime updatedAt, DateTime createdAt, @SubjectReviewStateConverter() SubjectReviewState reviewState, String? comment, int? priorityScore, DateTime? muteUntil, DateTime? muteReportingUntil, String? lastReviewedBy, DateTime? lastReviewedAt, DateTime? lastReportedAt, DateTime? lastAppealedAt, bool? takendown, bool? appealed, DateTime? suspendUntil, List<String>? tags, @AccountStatsConverter() AccountStats? accountStats, @RecordsStatsConverter() RecordsStats? recordsStats, @SubjectStatusViewAgeAssuranceStateConverter() SubjectStatusViewAgeAssuranceState? ageAssuranceState, @SubjectStatusViewAgeAssuranceUpdatedByConverter() SubjectStatusViewAgeAssuranceUpdatedBy? ageAssuranceUpdatedBy, Map<String, dynamic>? $unknown) $default,) {final _that = this;
switch (_that) {
case _SubjectStatusView():
return $default(_that.$type,_that.id,_that.subject,_that.hosting,_that.subjectBlobCids,_that.subjectRepoHandle,_that.updatedAt,_that.createdAt,_that.reviewState,_that.comment,_that.priorityScore,_that.muteUntil,_that.muteReportingUntil,_that.lastReviewedBy,_that.lastReviewedAt,_that.lastReportedAt,_that.lastAppealedAt,_that.takendown,_that.appealed,_that.suspendUntil,_that.tags,_that.accountStats,_that.recordsStats,_that.ageAssuranceState,_that.ageAssuranceUpdatedBy,_that.$unknown);case _:
throw StateError('Unexpected subclass');
}
}