whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
  1. TResult? implicit(
    1. String authorizationUrl,
    2. String? refreshUrl,
    3. Map<String, String> scopes
    )?,
  2. TResult? password(
    1. String tokenUrl,
    2. String? refreshUrl,
    3. Map<String, String> scopes
    )?,
  3. TResult? clientCredentials(
    1. String tokenUrl,
    2. String? refreshUrl,
    3. Map<String, String> scopes
    )?,
  4. TResult? authorizationCode(
    1. String authorizationUrl,
    2. String tokenUrl,
    3. String? refreshUrl,
    4. Map<String, String> scopes,
    )?,
})

A variant of when that fallback to returning null

It is equivalent to doing:

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

Implementation

@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult? Function( String authorizationUrl,  String? refreshUrl,  Map<String, String> scopes)?  implicit,TResult? Function( String tokenUrl,  String? refreshUrl,  Map<String, String> scopes)?  password,TResult? Function( String tokenUrl,  String? refreshUrl,  Map<String, String> scopes)?  clientCredentials,TResult? Function( String authorizationUrl,  String tokenUrl,  String? refreshUrl,  Map<String, String> scopes)?  authorizationCode,}) {final _that = this;
switch (_that) {
case _OAuthFlowImplicit() when implicit != null:
return implicit(_that.authorizationUrl,_that.refreshUrl,_that.scopes);case _OAuthFlowPassword() when password != null:
return password(_that.tokenUrl,_that.refreshUrl,_that.scopes);case _OAuthFlowClientCredentials() when clientCredentials != null:
return clientCredentials(_that.tokenUrl,_that.refreshUrl,_that.scopes);case _OAuthFlowAuthorizationCode() when authorizationCode != null:
return authorizationCode(_that.authorizationUrl,_that.tokenUrl,_that.refreshUrl,_that.scopes);case _:
  return null;

}
}