mapOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
  1. TResult? implicit(
    1. _OAuthFlowImplicit value
    )?,
  2. TResult? password(
    1. _OAuthFlowPassword value
    )?,
  3. TResult? clientCredentials(
    1. _OAuthFlowClientCredentials value
    )?,
  4. TResult? authorizationCode(
    1. _OAuthFlowAuthorizationCode value
    )?,
})

A variant of map that fallback to returning null.

It is equivalent to doing:

switch (sealedClass) {
  case final Subclass value:
    return ...;
  case _:
    return null;
}

Implementation

@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>({TResult? Function( _OAuthFlowImplicit value)?  implicit,TResult? Function( _OAuthFlowPassword value)?  password,TResult? Function( _OAuthFlowClientCredentials value)?  clientCredentials,TResult? Function( _OAuthFlowAuthorizationCode value)?  authorizationCode,}){
final _that = this;
switch (_that) {
case _OAuthFlowImplicit() when implicit != null:
return implicit(_that);case _OAuthFlowPassword() when password != null:
return password(_that);case _OAuthFlowClientCredentials() when clientCredentials != null:
return clientCredentials(_that);case _OAuthFlowAuthorizationCode() when authorizationCode != null:
return authorizationCode(_that);case _:
  return null;

}
}