getClip method

  1. @override
Path getClip(
  1. Size size
)
override

Returns a description of the clip given that the render object being clipped is of the given size.

Implementation

@override
Path getClip(Size size) {
  var h = size.height;
  var w = size.width;
  Path path = Path();

  // Left or Horizontal
  path.moveTo(0, 0);
  double x = 0;
  double y = 0;
  double i = h / points;

  if (edge == Edge.left || edge == Edge.horizontal || edge == Edge.all) {
    while (y < h) {
      y += i;
      x = (x == 0) ? depth : 0;
      path.lineTo(x, y);
    }
  }

  // Bottom or Vertical
  path.lineTo(0, h);
  x = 0;
  y = h;
  i = w / points;

  if (edge == Edge.bottom || edge == Edge.vertical || edge == Edge.all) {
    while (x < w) {
      x += i;
      y = (y == h) ? h - depth : h;
      path.lineTo(x, y);
    }
  }

  // Right or Horizontal
  path.lineTo(w, h);
  x = w;
  y = h;
  i = h / points;

  if (edge == Edge.right || edge == Edge.horizontal || edge == Edge.all) {
    while (y > 0) {
      y -= i;
      x = (x == w) ? w - depth : w;
      path.lineTo(x, y);
    }
  }

  // Top or Vertical
  path.lineTo(w, 0);
  x = w;
  y = 0;
  i = w / points;

  if (edge == Edge.top || edge == Edge.vertical || edge == Edge.all) {
    while (x > 0) {
      x -= i;
      y = (y == 0) ? depth : 0;
      path.lineTo(x, y);
    }
  }

  path.close();
  return path;
}