addBinary method Null safety

PartBuilder addBinary(
  1. Uint8List data,
  2. MediaType mediaType,
  3. {TransferEncoding transferEncoding = TransferEncoding.base64,
  4. ContentDispositionHeader? disposition,
  5. String? filename}

Adds a binary data part with the given data and optional filename.

mediaType The media type of the file. Specify the optional content disposition element, if it should not be populated automatically.


PartBuilder addBinary(Uint8List data, MediaType mediaType,
    {TransferEncoding transferEncoding = TransferEncoding.base64,
    ContentDispositionHeader? disposition,
    String? filename}) {
  disposition ??= ContentDispositionHeader.from(ContentDisposition.attachment,
      filename: filename, size: data.length);
  var child = addPart(disposition: disposition);
  child.transferEncoding = TransferEncoding.base64;

  child.setContentType(mediaType, name: filename);
  final info = AttachmentInfo(null, mediaType, filename, data.length,
      disposition.disposition, data, child);
  child._part.mimeData =
      TextMimeData(MailCodec.base64.encodeData(data), false);
  return child;