updateAvatar method
- NativeFile? file, {
- CropAreaInput? crop,
- void onSendProgress()?,
override
Updates or resets the MyUser.avatar field with the provided image
file.
Implementation
@override
Future<void> updateAvatar(
NativeFile? file, {
CropAreaInput? crop,
void Function(int count, int total)? onSendProgress,
}) async {
Log.debug(
'updateAvatar($file, crop: $crop, onSendProgress)',
'$runtimeType',
);
dio.MultipartFile? upload;
if (file != null) {
await file.ensureCorrectMediaType();
upload = await file.toMultipartFile();
}
final UserAvatar? avatar = myUser.value?.avatar;
if (file == null) {
myUser.update((u) => u?.avatar = null);
}
try {
await Backoff.run(
() async {
await _graphQlProvider.updateUserAvatar(
upload,
crop,
onSendProgress: onSendProgress,
);
},
retryIf: (e) => e.isNetworkRelated,
retries: 10,
);
} catch (_) {
if (file == null) {
myUser.update((u) => u?.avatar = avatar);
}
rethrow;
}
}