PathIconData.fromSvg constructor

PathIconData.fromSvg(
  1. String data, {
  2. PathFillType fillType = PathFillType.evenOdd,
})

Parse the data SVG document and merges all the shapes found in the document as a single path.

A fillType can be given, else PathFillType.evenOdd.

A semanticLabel is null and the document has an id attribute, then its value is used instead.

Implementation

factory PathIconData.fromSvg(
  String data, {
  PathFillType fillType = PathFillType.evenOdd,
}) {
  final document = XmlDocument.parse(data);

  if (document.rootElement.name.local != 'svg') {
    throw Exception('The provided is not an SVG content');
  }

  final viewBoxData = document.rootElement.getAttribute('viewBox');
  final viewBox = viewBoxData == null ? Rect.zero : parseViewBox(viewBoxData);
  final path = parseSvgElements(document.rootElement);

  if (path == null) {
    throw Exception('Empty path');
  }

  return PathIconData.sanitized(
    path: path,
    fillType: fillType,
    viewBox: viewBox,
  );
}