PathIconData.sanitized constructor

PathIconData.sanitized({
  1. required Path path,
  2. Rect? viewBox,
  3. PathFillType? fillType,
})

Create data from the given path.

If no viewBox is provided, then the bounds of the path are used and the path is translated at origin.

A fillType can override the given path's one.

Implementation

factory PathIconData.sanitized({
  required Path path,
  Rect? viewBox,
  PathFillType? fillType,
}) {
  final bounds = path.getBounds();

  if (viewBox == null) {
    path = Path()..addPath(path, -bounds.topLeft);
    if (fillType != null) {
      path.fillType = fillType;
    }
  } else if (fillType != null) {
    path = Path()..addPath(path, Offset.zero);
    path.fillType = fillType;
  }

  return PathIconData(
    viewBox: viewBox ?? (Offset.zero & bounds.size),
    path: path,
  );
}