render method Null safety

void render(
  1. StringBuffer buffer,
  2. {bool renderHeader = true}
)

Renders this mime part with all children parts into the specified buffer.

You can set renderHeader to false when the message headers should not be rendered.

Implementation

void render(StringBuffer buffer, {bool renderHeader = true}) {
  if (mimeData != null) {
    if (!mimeData!.containsHeader && renderHeader) {
      _renderHeaders(buffer);
      buffer.write('\r\n');
    }
    mimeData!.render(buffer);
  } else {
    if (renderHeader) {
      _renderHeaders(buffer);
      buffer.write('\r\n');
    }
    if (parts?.isNotEmpty ?? false) {
      final multiPartBoundary = getHeaderContentType()?.boundary;
      if (multiPartBoundary == null) {
        throw StateError(
            'mime message rendering error: parts present but no multiPartBoundary defined.');
      }
      for (final part in parts!) {
        buffer.write('--');
        buffer.write(multiPartBoundary);
        buffer.write('\r\n');
        part.render(buffer);
        buffer.write('\r\n');
      }
      buffer.write('--');
      buffer.write(multiPartBoundary);
      buffer.write('--');
      buffer.write('\r\n');
    }
  }
}