RoundedPolygon.rectangle constructor
- double width = 2,
- double height = 2,
- CornerRounding rounding = CornerRounding.unrounded,
- List<
CornerRounding> ? perVertexRounding, - double centerX = 0,
- double centerY = 0,
Creates a rectangular shape with the given width/height around the given center. Optional rounding parameters can be used to create a rounded rectangle instead.
As with all RoundedPolygon objects, if this shape is created with default dimensions and center, it is sized to fit within the 2x2 bounding box around a center of (0, 0) and will need to be scaled and moved using RoundedPolygon.transformed to fit the intended area in a UI.
width is the width of the rectangle, default value is 2.
height is the height of the rectangle, default value is 2.
rounding is the CornerRounding properties of every vertex. If some
vertices should have different rounding properties, then use
perVertexRounding instead. The default rounding value is
CornerRounding.unrounded, meaning that the polygon will use the
vertices themselves in the final shape and not curves rounded around the
vertices.
perVertexRounding is the CornerRounding properties of every vertex.
If this parameter is not null, then it must be of size 4 for the four
corners of the shape. If this parameter is null, then the polygon will
use the rounding parameter for every vertex instead. The default value
is null.
centerX is the X coordinate of the center of the rectangle, around which
all vertices will be placed equidistantly. The default center is at (0,0).
centerY is the Y coordinate of the center of the rectangle, around
which all vertices will be placed equidistantly. The default center is
at (0,0).
Implementation
factory RoundedPolygon.rectangle({
double width = 2,
double height = 2,
CornerRounding rounding = CornerRounding.unrounded,
List<CornerRounding>? perVertexRounding,
double centerX = 0,
double centerY = 0,
}) {
final left = centerX - width / 2;
final top = centerY - height / 2;
final right = centerX + width / 2;
final bottom = centerY + height / 2;
return RoundedPolygon.fromVertices(
[right, bottom, left, bottom, left, top, right, top],
rounding: rounding,
perVertexRounding: perVertexRounding,
centerX: centerX,
centerY: centerY,
);
}