when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- @JsonKey.new(name: 'customerID') String? id,
- @JsonKey.new(name: 'profileID') String? profileID,
- @JsonKey.new(name: 'id') String? customerID,
- @JsonKey.new(name: 'receivables_account') ReceivablesAccount? receivablesAccount,
- @JsonKey.new(name: 'active ') 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');
}
}