SvgElement.svg constructor Null safety

SvgElement.svg(
  1. String svg,
  2. {NodeValidator? validator,
  3. NodeTreeSanitizer? treeSanitizer}
)

Implementation

factory SvgElement.svg(String svg,
    {NodeValidator? validator, NodeTreeSanitizer? treeSanitizer}) {
  if (validator == null && treeSanitizer == null) {
    validator = new NodeValidatorBuilder.common()..allowSvg();
  }

  final match = _START_TAG_REGEXP.firstMatch(svg);
  Element parentElement;
  if (match != null && match.group(1)!.toLowerCase() == 'svg') {
    parentElement = document.body!;
  } else {
    parentElement = new SvgSvgElement();
  }
  var fragment = parentElement.createFragment(svg,
      validator: validator, treeSanitizer: treeSanitizer);
  return fragment.nodes.where((e) => e is SvgElement).single as SvgElement;
}