when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- PgRepo repo,
- PgStatus status,
- String error,
- PgLinkResponse? response,
- PgInvoiceResponse? pgInvoiceResponse,
- PgInvoiceResponse? pgInvoiceResponseError,
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( PgRepo repo, PgStatus status, String error, PgLinkResponse? response, PgInvoiceResponse? pgInvoiceResponse, PgInvoiceResponse? pgInvoiceResponseError) $default,) {final _that = this;
switch (_that) {
case _PgState():
return $default(_that.repo,_that.status,_that.error,_that.response,_that.pgInvoiceResponse,_that.pgInvoiceResponseError);case _:
throw StateError('Unexpected subclass');
}
}