paint method Null safety
- Canvas canvas,
- Rect rect,
- {TextDirection? textDirection,
- BoxShape shape = BoxShape.rectangle,
- BorderRadius? borderRadius}
override
Paints the border within the given Rect on the given Canvas.
Uniform borders are more efficient to paint than more complex borders.
You can provide a BoxShape to draw the border on. If the shape
in
BoxShape.circle, there is the requirement that the border isUniform.
If you specify a rectangular box shape (BoxShape.rectangle), then you
may specify a BorderRadius. If a borderRadius
is specified, there is
the requirement that the border isUniform.
The getInnerPath and getOuterPath methods do not know about the
shape
and borderRadius
arguments.
The textDirection
argument is not used by this paint method.
See also:
- paintBorder, which is used if the border is not uniform.
Implementation
@override
void paint(
Canvas canvas,
Rect rect, {
TextDirection? textDirection,
BoxShape shape = BoxShape.rectangle,
BorderRadius? borderRadius,
}) {
if (isUniform) {
switch (top.style) {
case BorderStyle.none:
return;
case BorderStyle.solid:
switch (shape) {
case BoxShape.circle:
assert(borderRadius == null, 'A borderRadius can only be given for rectangular boxes.');
BoxBorder._paintUniformBorderWithCircle(canvas, rect, top);
break;
case BoxShape.rectangle:
if (borderRadius != null) {
BoxBorder._paintUniformBorderWithRadius(canvas, rect, top, borderRadius);
return;
}
BoxBorder._paintUniformBorderWithRectangle(canvas, rect, top);
break;
}
return;
}
}
assert(() {
if (borderRadius != null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('A borderRadius can only be given for a uniform Border.'),
ErrorDescription('The following is not uniform:'),
if (!_colorIsUniform) ErrorDescription('BorderSide.color'),
if (!_widthIsUniform) ErrorDescription('BorderSide.width'),
if (!_styleIsUniform) ErrorDescription('BorderSide.style'),
if (!_strokeAlignIsUniform) ErrorDescription('BorderSide.strokeAlign'),
]);
}
return true;
}());
assert(() {
if (shape != BoxShape.rectangle) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('A Border can only be drawn as a circle if it is uniform.'),
ErrorDescription('The following is not uniform:'),
if (!_colorIsUniform) ErrorDescription('BorderSide.color'),
if (!_widthIsUniform) ErrorDescription('BorderSide.width'),
if (!_styleIsUniform) ErrorDescription('BorderSide.style'),
if (!_strokeAlignIsUniform) ErrorDescription('BorderSide.strokeAlign'),
]);
}
return true;
}());
assert(() {
if (!_strokeAlignIsUniform || top.strokeAlign != StrokeAlign.inside) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('A Border can only draw strokeAlign different than StrokeAlign.inside on uniform borders.'),
]);
}
return true;
}());
paintBorder(canvas, rect, top: top, right: right, bottom: bottom, left: left);
}