updateChatAvatar method
- PlatformFile? image, {
- CropAreaInput? crop,
Updates the Chat.avatar with the provided image
, or resets it to
null
.
Implementation
Future<void> updateChatAvatar(
PlatformFile? image, {
CropAreaInput? crop,
}) async {
avatarUpload.value = RxStatus.loading();
try {
await _chatService.updateChatAvatar(
chatId,
file: image == null ? null : NativeFile.fromPlatformFile(image),
crop: crop,
);
avatarUpload.value = RxStatus.empty();
} on UpdateChatAvatarException catch (e) {
switch (e.code) {
case UpdateChatAvatarErrorCode.dialog:
case UpdateChatAvatarErrorCode.invalidCropCoordinates:
case UpdateChatAvatarErrorCode.invalidCropPoints:
case UpdateChatAvatarErrorCode.unknownChat:
avatarUpload.value = RxStatus.error('err_data_transfer'.l10n);
case UpdateChatAvatarErrorCode.malformed:
case UpdateChatAvatarErrorCode.unsupportedFormat:
case UpdateChatAvatarErrorCode.invalidSize:
case UpdateChatAvatarErrorCode.invalidDimensions:
case UpdateChatAvatarErrorCode.artemisUnknown:
avatarUpload.value = RxStatus.error(e.toMessage());
}
} catch (e) {
avatarUpload.value = RxStatus.empty();
MessagePopup.error(e);
rethrow;
}
}