setContentType method Null safety

void setContentType(
  1. MediaType mediaType,
  2. {CharacterSet? characterSet,
  3. String? multiPartBoundary,
  4. String? name,
  5. Map<String, String>? parameters}
)

Creates the content-type based on the specified mediaType.

Optionally you can specify the characterSet, multiPartBoundary, name or other parameters.

Implementation

void setContentType(MediaType mediaType,
    {CharacterSet? characterSet,
    String? multiPartBoundary,
    String? name,
    Map<String, String>? parameters}) {
  if (mediaType.isMultipart && multiPartBoundary == null) {
    multiPartBoundary = MessageBuilder.createRandomId();
  }
  contentType = ContentTypeHeader.from(mediaType,
      charset: mediaType.top == MediaToptype.text
          ? MessageBuilder.getCharacterSetName(characterSet)
          : null,
      boundary: multiPartBoundary);
  if (name != null) {
    contentType!.parameters['name'] = '"$name"';
  }
  if (parameters?.isNotEmpty ?? false) {
    contentType!.parameters.addAll(parameters!);
  }
}