setAvatar method Null safety

Future<Patient?> setAvatar(
  1. {required Patient patient,
  2. required MediaAsset asset}
)

Sets the referenced asset as patient avatar. The asset already needs to be present in the CMS and must not be a local asset. When done, causes the repository to emit an updated patient instance with the avatar referenced as remote URL.

Implementation

Future<Patient?> setAvatar(
    {required final Patient patient, required final MediaAsset asset}) async {
  final result = await setUserAvatar(user: patient, asset: asset);

  if (result) {
    final modifiedPatient =
        patient.rebuild((p) => p..avatar = asset.toBuilder());

    _sendPatientUpdate(patient: modifiedPatient);

    return modifiedPatient;
  }

  return null;
}