when<TResult extends Object?> method
- @optionalTypeArgs
- required TResult implicit(),
- required TResult password(),
- required TResult clientCredentials(),
- required TResult authorizationCode(),
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');
}
}