hasPart method Null safety

bool hasPart(
  1. MediaSubtype subtype,
  2. {int? depth}
)

Checks if this MIME part or a child is of the specified media type

subtype the desired media type depth optional depth, use 1 if only direct children should be checked

Implementation

bool hasPart(MediaSubtype subtype, {int? depth}) {
  if (mediaType.sub == subtype) {
    return true;
  }
  final mimeParts = parts;
  if (mimeParts != null) {
    if (depth != null) {
      if (--depth < 0) {
        return false;
      }
    }
    for (final part in mimeParts) {
      if (part.hasPart(subtype, depth: depth)) {
        return true;
      }
    }
  }
  return false;
}