when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String? id,
    2. String? address1,
    3. String? address2,
    4. String? city,
    5. String? company,
    6. String? country,
    7. String? countryCode,
    8. String? firstName,
    9. String? lastName,
    10. String? formattedArea,
    11. String? latitude,
    12. String? longitude,
    13. String? name,
    14. String? phone,
    15. String? province,
    16. String? provinceCode,
    17. String? zip,
    )
)

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,  String? address1,  String? address2,  String? city,  String? company,  String? country,  String? countryCode,  String? firstName,  String? lastName,  String? formattedArea,  String? latitude,  String? longitude,  String? name,  String? phone,  String? province,  String? provinceCode,  String? zip)  $default,) {final _that = this;
switch (_that) {
case _Address():
return $default(_that.id,_that.address1,_that.address2,_that.city,_that.company,_that.country,_that.countryCode,_that.firstName,_that.lastName,_that.formattedArea,_that.latitude,_that.longitude,_that.name,_that.phone,_that.province,_that.provinceCode,_that.zip);case _:
  throw StateError('Unexpected subclass');

}
}