when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- String id,
- @JsonKey.new(defaultValue: '') String address1,
- @JsonKey.new(defaultValue: '') String city,
- @JsonKey.new(defaultValue: '') String country,
- String? zip,
- String? lastName,
- String? name,
- String? firstName,
- String? address2,
- String? company,
- String? countryCodeV2,
- String? formattedArea,
- double? latitude,
- double? longitude,
- String? phone,
- String? province,
- String? provinceCode,
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( String id, @JsonKey(defaultValue: '') String address1, @JsonKey(defaultValue: '') String city, @JsonKey(defaultValue: '') String country, String? zip, String? lastName, String? name, String? firstName, String? address2, String? company, String? countryCodeV2, String? formattedArea, double? latitude, double? longitude, String? phone, String? province, String? provinceCode) $default,) {final _that = this;
switch (_that) {
case _MailingAddress():
return $default(_that.id,_that.address1,_that.city,_that.country,_that.zip,_that.lastName,_that.name,_that.firstName,_that.address2,_that.company,_that.countryCodeV2,_that.formattedArea,_that.latitude,_that.longitude,_that.phone,_that.province,_that.provinceCode);case _:
throw StateError('Unexpected subclass');
}
}