RoundedPolygon.pill constructor
A pill shape consists of a rectangle shape bounded by two semicircles at either of the long ends of the rectangle.
width is the width of the resulting shape.
[height is the height of the resulting shape.
smoothing the amount by which the arc is "smoothed" by extending the
curve from the circular arc on each endcap to the edge between the
endcaps. A value of 0 (no smoothing) indicates that the corner is rounded
by only a circular arc.
centerX is the X coordinate of the center of the polygon, around which
all vertices will be placed. The default center is at (0,0).
centerY is the Y coordinate of the center of the polygon, around which
all vertices will be placed. The default center is at (0,0).
Throws ArgumentError if either width or height are <= 0.
Implementation
factory RoundedPolygon.pill({
double width = 2,
double height = 1,
double smoothing = 0,
double centerX = 0,
double centerY = 0,
}) {
if (width <= 0 || height <= 0) {
throw ArgumentError('Pill shapes must have positive width and height.');
}
final wHalf = width / 2;
final hHalf = height / 2;
return RoundedPolygon.fromVertices(
[
wHalf + centerX,
hHalf + centerY,
-wHalf + centerX,
hHalf + centerY,
-wHalf + centerX,
-hHalf + centerY,
wHalf + centerX,
-hHalf + centerY,
],
rounding: CornerRounding(
radius: math.min(wHalf, hHalf),
smoothing: smoothing,
),
centerX: centerX,
centerY: centerY,
);
}