pickAvatar method

Future<void> pickAvatar()

Opens a file choose popup and updates the Chat.avatar with the selected image, if any.

Implementation

Future<void> pickAvatar() async {
  final FilePickerResult? result = await PlatformUtils.pickFiles(
    type: FileType.custom,
    allowedExtensions: NativeFile.images,
    allowMultiple: false,
    withData: true,
    lockParentWindow: true,
  );

  if (result != null) {
    final PlatformFile file = result.files.first;

    final CropAreaInput? crop = await CropAvatarView.show(
      router.context!,
      file.bytes!,
    );
    if (crop == null) {
      return;
    }

    await updateChatAvatar(file, crop: crop);
  }
}