getEdgesBarPath method

Path getEdgesBarPath(
  1. Size size, {
  2. required Offset centerLeft,
  3. required Offset centerRight,
  4. required double halfLineWidth,
})

Implementation

Path getEdgesBarPath(
  Size size, {
  required Offset centerLeft,
  required Offset centerRight,
  required double halfLineWidth,
}) {
  if (style.borderRadius == 0) {
    return Path()
      // LEFT EDGE
      ..addRect(
        Rect.fromCenter(
          center: centerLeft,
          width: style.edgesSize,
          height: size.height + style.lineWidth * 2,
        ),
      )
      // RIGTH EDGE
      ..addRect(
        Rect.fromCenter(
          center: centerRight,
          width: style.edgesSize,
          height: size.height + style.lineWidth * 2,
        ),
      );
  }

  final borderRadius = Radius.circular(style.borderRadius);

  /// Return left and right edges, with a reversed border radius on the inside of the rect
  return Path()
    // LEFT EDGE
    ..addPath(
      Path.combine(
        PathOperation.difference,
        Path()
          ..addRRect(
            RRect.fromRectAndCorners(
              Rect.fromLTWH(
                centerLeft.dx - halfLineWidth,
                -style.lineWidth,
                style.edgeWidth + style.borderRadius,
                size.height + style.lineWidth * 2,
              ),
              topLeft: borderRadius,
              bottomLeft: borderRadius,
            ),
          ),
        Path()
          ..addRRect(
            RRect.fromRectAndCorners(
              Rect.fromLTWH(
                centerLeft.dx + halfLineWidth,
                0.0,
                style.borderRadius,
                size.height,
              ),
              topLeft: borderRadius,
              bottomLeft: borderRadius,
            ),
          ),
      ),
      Offset.zero,
    )
    // RIGHT EDGE
    ..addPath(
      Path.combine(
        PathOperation.difference,
        Path()
          ..addRRect(
            RRect.fromRectAndCorners(
              Rect.fromLTWH(
                centerRight.dx - halfLineWidth - style.borderRadius,
                -style.lineWidth,
                style.edgeWidth + style.borderRadius,
                size.height + style.lineWidth * 2,
              ),
              topRight: borderRadius,
              bottomRight: borderRadius,
            ),
          ),
        Path()
          ..addRRect(
            RRect.fromRectAndCorners(
              Rect.fromLTWH(
                centerRight.dx - halfLineWidth - style.borderRadius,
                0.0,
                style.borderRadius,
                size.height,
              ),
              topRight: borderRadius,
              bottomRight: borderRadius,
            ),
          ),
      ),
      Offset.zero,
    );
}