when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. @JsonKey.new(defaultValue: '') String address1,
    3. @JsonKey.new(defaultValue: '') String city,
    4. @JsonKey.new(defaultValue: '') String country,
    5. String? zip,
    6. String? lastName,
    7. String? name,
    8. String? firstName,
    9. String? address2,
    10. String? company,
    11. String? countryCodeV2,
    12. String? formattedArea,
    13. double? latitude,
    14. double? longitude,
    15. String? phone,
    16. String? province,
    17. 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');

}
}