whenOrNull<TResult extends Object?> method
TResult?
whenOrNull<TResult extends Object?>(
- TResult? $default(
- String id,
- bool active,
- bool counselled,
- List<
ClientType> clientTypes, - String treatmentEnrollmentDate,
- String treatmentBuddy,
- User? user,
- String chvUserID,
- String chvUserName,
- List<
Identifier> identifiers, - String fhirPatientID,
- String healthRecordID,
- String caregiverID,
- Facility? defaultFacility,
- Program? program,
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') String id, @JsonKey(name: 'active') bool active, @JsonKey(name: 'clientCounselled') bool counselled, @JsonKey(name: 'clientTypes') List<ClientType> clientTypes, @JsonKey(name: 'treatmentEnrollmentDate') String treatmentEnrollmentDate, @JsonKey(name: 'treatmentBuddy') String treatmentBuddy, @JsonKey(name: 'user') User? user, @JsonKey(name: 'chvUserID') String chvUserID, @JsonKey(name: 'chvUserName') String chvUserName, @JsonKey(name: 'identifiers') List<Identifier> identifiers, @JsonKey(name: 'fhirPatientID') String fhirPatientID, @JsonKey(name: 'healthRecordID') String healthRecordID, @JsonKey(name: 'caregiverID') String caregiverID, @JsonKey(name: 'defaultFacility') Facility? defaultFacility, @JsonKey(name: 'program') Program? program)? $default,) {final _that = this;
switch (_that) {
case _ClientProfile() when $default != null:
return $default(_that.id,_that.active,_that.counselled,_that.clientTypes,_that.treatmentEnrollmentDate,_that.treatmentBuddy,_that.user,_that.chvUserID,_that.chvUserName,_that.identifiers,_that.fhirPatientID,_that.healthRecordID,_that.caregiverID,_that.defaultFacility,_that.program);case _:
return null;
}
}