editAvatar method
Opens the CropAvatarView to update the MyUser.avatar with the CropAreaInput returned from it.
Implementation
Future<void> editAvatar() async {
final ImageFile? file = chat?.chat.value.avatar?.original;
if (file == null) {
return;
}
avatarUpload.value = RxStatus.loading();
try {
final CacheEntry cache = await CacheWorker.instance.get(
url: file.url,
checksum: file.checksum,
);
if (cache.bytes != null) {
final CropAreaInput? crop = await CropAvatarView.show(
router.context!,
cache.bytes!,
);
if (crop != null) {
await _chatService.updateChatAvatar(
chatId,
file: NativeFile(
name: file.name,
size: cache.bytes!.lengthInBytes,
bytes: cache.bytes,
),
crop: crop,
);
}
}
} finally {
avatarUpload.value = RxStatus.empty();
}
}