buildLocalPath method

Path? buildLocalPath()

Builds a local path centered around (0,0), or returns null if invalid.

The returned path is in the node's local coordinate space. The caller is responsible for applying transform.

Implementation

Path? buildLocalPath() {
  if (_cacheResolved &&
      _cachedSvgPathData == _svgPathData &&
      _cachedFillRule == _fillRule) {
    return _cachedLocalPath;
  }
  if (_svgPathData.trim().isEmpty) {
    _cacheResolved = true;
    _cachedSvgPathData = _svgPathData;
    _cachedFillRule = _fillRule;
    _cachedLocalPath = null;
    return null;
  }
  try {
    final path = parseSvgPathData(_svgPathData);
    final bounds = path.getBounds();
    if (bounds.isEmpty) {
      _cacheResolved = true;
      _cachedSvgPathData = _svgPathData;
      _cachedFillRule = _fillRule;
      _cachedLocalPath = null;
      return null;
    }
    final centered = path.shift(-bounds.center);
    centered.fillType = _fillRule == PathFillRule.evenOdd
        ? PathFillType.evenOdd
        : PathFillType.nonZero;
    _cacheResolved = true;
    _cachedSvgPathData = _svgPathData;
    _cachedFillRule = _fillRule;
    _cachedLocalPath = centered;
    return centered;
  } catch (_) {
    _cacheResolved = true;
    _cachedSvgPathData = _svgPathData;
    _cachedFillRule = _fillRule;
    _cachedLocalPath = null;
    return null;
  }
}