whenOrNull<TResult extends Object?> method
TResult?
whenOrNull<TResult extends Object?>()
A variant of when that fallback to returning null
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case _:
return null;
}
Implementation
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function(
@JsonKey(name: 'id') int id,
@JsonKey(name: 'account_id') int accountId,
@JsonKey(name: 'address') String address,
@JsonKey(name: 'city') String city,
@JsonKey(name: 'zip_code') String zipCode,
@JsonKey(name: 'province') String province,
@JsonKey(name: 'country') String country,
@JsonKey(name: 'tax_code') String? taxCode,
@JsonKey(name: 'vat_number') String? vatNumber,
@JsonKey(name: 'business_name') String? businessName,
@JsonKey(name: 'deleted_at') DateTime? deletedAt,
@JsonKey(name: 'created_at') DateTime? createdAt,
@JsonKey(name: 'updated_at') DateTime? updatedAt)?
$default,
) {
final _that = this;
switch (_that) {
case _AccountAddress() when $default != null:
return $default(
_that.id,
_that.accountId,
_that.address,
_that.city,
_that.zipCode,
_that.province,
_that.country,
_that.taxCode,
_that.vatNumber,
_that.businessName,
_that.deletedAt,
_that.createdAt,
_that.updatedAt);
case _:
return null;
}
}