maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. bool active,
    3. bool counselled,
    4. List<ClientType> clientTypes,
    5. String treatmentEnrollmentDate,
    6. String treatmentBuddy,
    7. User? user,
    8. String chvUserID,
    9. String chvUserName,
    10. List<Identifier> identifiers,
    11. String fhirPatientID,
    12. String healthRecordID,
    13. String caregiverID,
    14. Facility? defaultFacility,
    15. Program? program,
    )?, {
  2. required TResult orElse(),
})

A variant of when that fallback to an orElse callback.

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return orElse();
}

Implementation

@optionalTypeArgs TResult maybeWhen<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,{required TResult orElse(),}) {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 orElse();

}
}