attachmentOnTap method

Future<void> attachmentOnTap(
  1. dynamic ref,
  2. dynamic context,
  3. dynamic attachmentType,
  4. dynamic mediaState,
)

Implementation

Future<void> attachmentOnTap(
  WidgetRef ref,
  BuildContext context,
  AttachmentType attachmentType,
  AttachmentMediaState mediaState,
) async {
  // Open attachment link
  if (attachmentType == AttachmentType.link) {
    openLink(attachment.link() ?? '', context);
  } else if (mediaState.mediaFile == null) {
    // If attachment is media then check media is downloaded
    // If attachment not downloaded
    ref
        .read(attachmentMediaStateProvider(attachment).notifier)
        .downloadMedia();
  } else {
    // If attachment is downloaded and image or video
    if (attachmentType == AttachmentType.image ||
        attachmentType == AttachmentType.video) {
      final msgContent = attachment.msgContent();
      showAdaptiveDialog(
        context: context,
        barrierDismissible: false,
        useRootNavigator: false,
        builder: (context) {
          if (attachmentType == AttachmentType.image) {
            return ImageDialog(
              title: msgContent.body(),
              imageFile: mediaState.mediaFile!,
            );
          } else {
            return VideoDialog(
              title: msgContent.body(),
              videoFile: mediaState.mediaFile!,
            );
          }
        },
      );
    }
    // If attachment is downloaded and file or others
    else {
      openFileShareDialog(context: context, file: mediaState.mediaFile!);
    }
  }
}