uploadAvatar method
Crops and uploads an image and sets it as MyUser.avatar and MyUser.callCover.
Implementation
Future<void> uploadAvatar() async {
try {
final FilePickerResult? result = await PlatformUtils.pickFiles(
type: FileType.image,
allowedExtensions: NativeFile.images,
allowMultiple: false,
withData: true,
lockParentWindow: true,
);
if (result?.files.isNotEmpty == true) {
avatarUpload.value = RxStatus.loading();
final PlatformFile file = result!.files.first;
final CropAreaInput? crop = await CropAvatarView.show(
router.context!,
file.bytes!,
);
if (crop == null) {
return;
}
await _updateAvatar(
NativeFile.fromPlatformFile(result.files.first),
crop,
);
}
} finally {
avatarUpload.value = RxStatus.empty();
}
}