when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String? id,
- String? profileID,
- String? customerID,
- ReceivablesAccount? receivablesAccount,
- bool? active,
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(@JsonKey(name: 'customerID') String? id, @JsonKey(name: 'profileID') String? profileID, @JsonKey(name: 'id') String? customerID, @JsonKey(name: 'receivables_account') ReceivablesAccount? receivablesAccount, @JsonKey(name: 'active ') bool? active) $default,) {final _that = this;
switch (_that) {
case _Customer():
return $default(_that.id,_that.profileID,_that.customerID,_that.receivablesAccount,_that.active);case _:
throw StateError('Unexpected subclass');
}
}