paintInterior method
- Canvas canvas,
- Rect rect,
- Paint paint, {
- TextDirection? textDirection,
Paint a canvas with the appropriate shape.
On ShapeBorder subclasses whose preferPaintInterior method returns true, this should be faster than using Canvas.drawPath with the path provided by getOuterPath. (If preferPaintInterior returns false, then this method asserts in debug mode and does nothing in release mode.)
Subclasses are expected to implement this method when the Canvas API has a dedicated method to draw the relevant shape. For example, CircleBorder uses this to call Canvas.drawCircle, and RoundedRectangleBorder uses this to call Canvas.drawRRect.
Subclasses that implement this must ensure that calling paintInterior is semantically equivalent to (i.e. renders the same pixels as) calling Canvas.drawPath with the same Paint and the Path returned from getOuterPath, and must also override preferPaintInterior to return true.
For example, a shape that draws a rectangle might implement getOuterPath, paintInterior, and preferPaintInterior as follows:
class RectangleBorder extends OutlinedBorder {
// ...
@override
Path getOuterPath(Rect rect, { TextDirection? textDirection }) {
return Path()
..addRect(rect);
}
@override
void paintInterior(Canvas canvas, Rect rect, Paint paint, {TextDirection? textDirection}) {
canvas.drawRect(rect, paint);
}
@override
bool get preferPaintInterior => true;
// ...
}
When a shape can only be drawn using path, preferPaintInterior must return false. In that case, classes such as ShapeDecoration will cache the path from getOuterPath and call Canvas.drawPath directly.
Implementation
void paintInterior(Canvas canvas, Rect rect, Paint paint, {TextDirection? textDirection}) {
assert(!preferPaintInterior, '$runtimeType.preferPaintInterior returns true but $runtimeType.paintInterior is not implemented.');
assert(false, '$runtimeType.preferPaintInterior returns false, so it is an error to call its paintInterior method.');
}