when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String $type,
- AtUri uri,
- String cid,
- String did,
- ProfileView creator,
- String displayName,
- String? description,
- List<
RichtextFacet> ? descriptionFacets, - String? avatar,
- int? likeCount,
- bool? acceptsInteractions,
- List<
Label> ? labels, - GeneratorViewerState? viewer,
- GeneratorViewContentMode? contentMode,
- DateTime indexedAt,
- 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, @AtUriConverter() AtUri uri, String cid, String did, @ProfileViewConverter() ProfileView creator, String displayName, String? description, @RichtextFacetConverter() List<RichtextFacet>? descriptionFacets, String? avatar, int? likeCount, bool? acceptsInteractions, @LabelConverter() List<Label>? labels, @GeneratorViewerStateConverter() GeneratorViewerState? viewer, @GeneratorViewContentModeConverter() GeneratorViewContentMode? contentMode, DateTime indexedAt, Map<String, dynamic>? $unknown) $default,) {final _that = this;
switch (_that) {
case _GeneratorView():
return $default(_that.$type,_that.uri,_that.cid,_that.did,_that.creator,_that.displayName,_that.description,_that.descriptionFacets,_that.avatar,_that.likeCount,_that.acceptsInteractions,_that.labels,_that.viewer,_that.contentMode,_that.indexedAt,_that.$unknown);case _:
throw StateError('Unexpected subclass');
}
}