paint method Null safety
- Canvas canvas,
- Rect rect,
- {TextDirection? textDirection}
override
Paints the border within the given Rect on the given Canvas.
The textDirection
argument must be provided and non-null if the border
has a text direction dependency (for example if it is expressed in terms
of "start" and "end" instead of "left" and "right"). It may be null if
the border will not need the text direction to paint itself.
Implementation
@override
void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) {
switch (side.style) {
case BorderStyle.none:
break;
case BorderStyle.solid:
if (eccentricity != 0.0) {
final Rect borderRect = _adjustRect(rect);
final Rect adjustedRect;
switch (side.strokeAlign) {
case StrokeAlign.inside:
adjustedRect = borderRect.deflate(side.width / 2.0);
break;
case StrokeAlign.center:
adjustedRect = borderRect;
break;
case StrokeAlign.outside:
adjustedRect = borderRect.inflate(side.width / 2.0);
break;
}
canvas.drawOval(adjustedRect, side.toPaint());
} else {
final double radius;
switch (side.strokeAlign) {
case StrokeAlign.inside:
radius = (rect.shortestSide - side.width) / 2.0;
break;
case StrokeAlign.center:
radius = rect.shortestSide / 2.0;
break;
case StrokeAlign.outside:
radius = (rect.shortestSide + side.width) / 2.0;
break;
}
canvas.drawCircle(rect.center, radius, side.toPaint());
}
}
}