A widget that provides a canvas on which to draw during the paint phase.
When asked to paint, CustomPaint first asks its painter to paint on the current canvas, then it paints its child, and then, after painting its child, it asks its foregroundPainter to paint. The coodinate system of the canvas matches the coordinate system of the CustomPaint object. The painters are expected to paint within a rectangle starting at the origin and encompassing a region of the given size. (If the painters paint outside those bounds, there might be insufficient memory allocated to rasterize the painting commands and the resulting behavior is undefined.)
Painters are implemented by subclassing CustomPainter.
Because custom paint calls its painters during paint, you cannot call
setState
or markNeedsLayout
during the callback (the layout for this
frame has already happened).
Custom painters normally size themselves to their child. If they do not have a child, they attempt to size themselves to the size, which defaults to Size.zero.
See also:
- Inheritance
- Object
- Widget
- RenderObjectWidget
- SingleChildRenderObjectWidget
- CustomPaint
Constructors
- CustomPaint({Key key, CustomPainter painter, CustomPainter foregroundPainter, Size size: Size.zero, Widget child })
-
Creates a widget that delegates its painting.
Properties
- foregroundPainter → CustomPainter
-
The painter that paints after the children.
read-only - painter → CustomPainter
-
The painter that paints before the children.
read-only - size → Size
-
The size that this CustomPaint should aim for, given the layout constraints, if there is no child.
read-only - child → Widget
-
The widget below this widget in the tree.
read-only, inherited - hashCode → int
-
Get a hash code for this object.
read-only, inherited - key → Key
-
Controls how one widget replaces another widget in the tree.
read-only, inherited - runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Operators
-
operator ==(
other) → bool -
The equality operator.
inherited
Methods
-
createRenderObject(
BuildContext context) → RenderCustomPaint -
Creates an instance of the
RenderObject
class that thisRenderObjectWidget
represents, using the configuration described by thisRenderObjectWidget
. -
didUnmountRenderObject(
RenderCustomPaint renderObject) → void -
A render object previously associated with this widget has been removed from the tree. The given
RenderObject
will be of the same type as returned by this object'screateRenderObject
. -
updateRenderObject(
BuildContext context, RenderCustomPaint renderObject) → void -
Copies the configuration described by this
RenderObjectWidget
to the givenRenderObject
, which will be of the same type as returned by this object'screateRenderObject
. -
createElement(
) → SingleChildRenderObjectElement -
RenderObjectWidgets always inflate to a
RenderObjectElement
subclass.inherited -
debugFillDescription(
List<String> description) → void -
Add additional information to the given description for use by toString.
inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited -
toString(
) → String -
Returns a string representation of this object.
inherited -
toStringShort(
) → String -
A short, textual description of this widget.
inherited