when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String $type,
- String did,
- String handle,
- String? email,
- DateTime indexedAt,
- ModerationDetail moderation,
- List<
Label> ? labels, - InviteCode? invitedBy,
- List<
InviteCode> ? invites, - bool? invitesDisabled,
- String? inviteNote,
- DateTime? emailConfirmedAt,
- DateTime? deactivatedAt,
- List<
ThreatSignature> ? threatSignatures, - 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 did, String handle, String? email, List<Map<String, dynamic>> relatedRecords, DateTime indexedAt, @ModerationDetailConverter() ModerationDetail moderation, @LabelConverter() List<Label>? labels, @InviteCodeConverter() InviteCode? invitedBy, @InviteCodeConverter() List<InviteCode>? invites, bool? invitesDisabled, String? inviteNote, DateTime? emailConfirmedAt, DateTime? deactivatedAt, @ThreatSignatureConverter() List<ThreatSignature>? threatSignatures, Map<String, dynamic>? $unknown) $default,) {final _that = this;
switch (_that) {
case _RepoViewDetail():
return $default(_that.$type,_that.did,_that.handle,_that.email,_that.relatedRecords,_that.indexedAt,_that.moderation,_that.labels,_that.invitedBy,_that.invites,_that.invitesDisabled,_that.inviteNote,_that.emailConfirmedAt,_that.deactivatedAt,_that.threatSignatures,_that.$unknown);case _:
throw StateError('Unexpected subclass');
}
}