when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String $type,
    2. String code,
    3. String name,
    4. @ProfileViewBasicConverter() ProfileViewBasic owner,
    5. int memberCount,
    6. int memberLimit,
    7. bool requireApproval,
    8. @JoinRuleConverter() JoinRule joinRule,
    9. @LinkEnabledStatusConverter() LinkEnabledStatus enabledStatus,
    10. @ConvoViewConverter() ConvoView? convo,
    11. @JoinLinkViewerStateConverter() JoinLinkViewerState? viewer,
    12. 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 code,  String name, @ProfileViewBasicConverter()  ProfileViewBasic owner,  int memberCount,  int memberLimit,  bool requireApproval, @JoinRuleConverter()  JoinRule joinRule, @LinkEnabledStatusConverter()  LinkEnabledStatus enabledStatus, @ConvoViewConverter()  ConvoView? convo, @JoinLinkViewerStateConverter()  JoinLinkViewerState? viewer,  Map<String, dynamic>? $unknown)  $default,) {final _that = this;
switch (_that) {
case _JoinLinkPreviewView():
return $default(_that.$type,_that.code,_that.name,_that.owner,_that.memberCount,_that.memberLimit,_that.requireApproval,_that.joinRule,_that.enabledStatus,_that.convo,_that.viewer,_that.$unknown);case _:
  throw StateError('Unexpected subclass');

}
}