when<TResult extends Object?> method

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

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?>({required TResult Function( String authorizationUrl,  String? refreshUrl,  Map<String, String> scopes)  implicit,required TResult Function( String tokenUrl,  String? refreshUrl,  Map<String, String> scopes)  password,required TResult Function( String tokenUrl,  String? refreshUrl,  Map<String, String> scopes)  clientCredentials,required TResult Function( String authorizationUrl,  String tokenUrl,  String? refreshUrl,  Map<String, String> scopes)  authorizationCode,}) {final _that = this;
switch (_that) {
case _OAuthFlowImplicit():
return implicit(_that.authorizationUrl,_that.refreshUrl,_that.scopes);case _OAuthFlowPassword():
return password(_that.tokenUrl,_that.refreshUrl,_that.scopes);case _OAuthFlowClientCredentials():
return clientCredentials(_that.tokenUrl,_that.refreshUrl,_that.scopes);case _OAuthFlowAuthorizationCode():
return authorizationCode(_that.authorizationUrl,_that.tokenUrl,_that.refreshUrl,_that.scopes);case _:
  throw StateError('Unexpected subclass');

}
}