saveAttachmentNote method
Implementation
Future<void> saveAttachmentNote(BuildContext context) async {
try {
isSavingAttachmentNote.value = true;
sendingAttachments.value++;
update();
bool conversationExists = await checkConversationExists(1);
if (!conversationExists) return;
Attachment? attachment = openAttachmentNote.value == null
? await AttachmentService.postNoteAttachment(
noteName.value,
noteContent.value,
)
: await AttachmentService.patchNoteAttachment(
openAttachmentNote.value!.id,
noteName.value,
noteContent.value,
);
if (attachment != null) {
if (openAttachmentNote.value == null) {
attachments.add(attachment);
} else {
attachments[attachments.indexOf(openAttachmentNote.value!)] =
attachment;
}
attachments.refresh();
update();
}
// ignore: use_build_context_synchronously
Navigator.pop(context);
isSavingAttachmentNote.value = false;
sendingAttachments.value--;
update();
} catch (e) {
isSavingAttachmentNote.value = false;
update();
}
}