imageAttachmentDraft method

Future imageAttachmentDraft({
  1. String? filepath,
})

Implementation

Future<AttachmentDraft> imageAttachmentDraft({String? filepath}) async {
  // ensure attachments exists and permissible to post
  final attachmentsFinder =
      find.byKey(AttachmentSectionWidget.attachmentsKey);
  final attachmentWidget = attachmentsFinder.evaluate().first.widget
      as FoundAttachmentSectionWidget;
  final attachmentsManager = attachmentWidget.attachmentManager;
  await attachmentsFinder.should(findsOneWidget);
  final addAttachmentFinder =
      find.byKey(AttachmentSectionWidget.addAttachmentBtnKey);
  await addAttachmentFinder.should(findsOneWidget);
  //
  final imageFile = await convertAssetImageToXFile(
    filepath ?? 'assets/images/update_onboard.png',
  );
  final context = tester.element(addAttachmentFinder);
  final ref = ProviderScope.containerOf(context);
  final client = ref.read(alwaysClientProvider);

  Uint8List bytes = await imageFile.readAsBytes();
  final decodedImage = await decodeImageFromList(bytes);
  final imageDraft = client
      .imageDraft(imageFile.path, 'image/')
      .size(bytes.length)
      .width(decodedImage.width)
      .height(decodedImage.height);
  final attachmentDraft = await attachmentsManager.contentDraft(imageDraft);
  return attachmentDraft;
}