FileAttachment.fileOrImage constructor

FileAttachment.fileOrImage({
  1. required String name,
  2. required String mimeType,
  3. required Uint8List bytes,
})

Factory constructor for creating either a FileAttachment or an ImageFileAttachment.

This factory method determines the type of attachment based on the MIME type. If the MIME type indicates an image, it creates an ImageFileAttachment. Otherwise, it creates a FileAttachment.

name is the name of the attachment. mimeType is the MIME type of the attachment. bytes is the binary content of the attachment.

Returns an instance of either FileAttachment or ImageFileAttachment.

Implementation

factory FileAttachment.fileOrImage({
  required String name,
  required String mimeType,
  required Uint8List bytes,
}) => Attachment._isImage(mimeType)
    ? ImageFileAttachment(name: name, mimeType: mimeType, bytes: bytes)
    : FileAttachment(name: name, mimeType: mimeType, bytes: bytes);