RenderObject class abstract
A render object of the tree a PipelineOwner lays out and paints.
A subclass sets its width and height within the constraints it is given in performLayout, laying out its children there first (layout) and placing each by its parentData; and draws itself in paint, at the canvas origin and clipped to its bounds, its children with paintChild. A change to what it shows marks it: markNeedsLayout for one that may change its size or its children's, markNeedsPaint for one that only changes how it looks. An object with children mixes in RenderObjectWithChildMixin or ContainerRenderObjectMixin, which keep them, visit them and hit test them.
A label as wide as its text, one row tall:
final class RenderLabel extends RenderObject {
RenderLabel(this._label, this.pen);
final int pen;
String _label;
set label(String l) {
_label = l;
markNeedsLayout();
}
@override
void performLayout(BoxConstraints c) {
width = c.constrainWidth(_label.length);
height = c.constrainHeight(1);
}
@override
void paint(PaintContext ctx) => ctx.canvas.text(0, 0, _label, pen);
}
An exception its performLayout or paint throws stays in it: the object shows the error's message in white on red in its place, clipped to its bounds, and the owner reports it (PipelineOwner.onError). After a layout that threw, the object is as big as the message within its constraints, and shows it until it lays out without throwing; after a paint that threw, until it is marked for paint (markNeedsPaint) or laid out again, which paints it again.
- Implementers
- ContainerRenderObjectMixin
- RenderBox
- RenderConstrainedBox
- RenderDecoratedBox
- RenderDivider
- RenderEffect
- RenderErrorBox
- RenderFlex
- RenderFractionallySizedBox
- RenderGrid
- RenderIntrinsicHeight
- RenderIntrinsicWidth
- RenderList
- RenderLog
- RenderObjectWithChildMixin
- RenderPadding
- RenderParagraph
- RenderPositionedBox
- RenderStack
- RenderText
- RenderViewport
- RenderWrap
Constructors
- RenderObject()
- An object with no parent, no owner and no size yet, for a subclass to construct.
Properties
- checkedBeforePaint ↔ bool
-
Whether beforePaint is called while this object is attached. Off by
default.
getter/setter pair
- constraints → BoxConstraints?
-
The constraints of the last layout; null before the first.
no setter
- debugError → String?
-
The message of the error this object shows in its place, which its
layout or paint threw; null when it shows itself.
no setter
- debugNeedsLayout → bool
-
Whether this object is to be laid out on the next frame.
no setter
- debugNeedsPaint → bool
-
Whether this object, a repaint boundary or the root, is to be
repainted on the next frame (markNeedsPaint inside it).
no setter
- depth → int
-
How many ancestors this object has: 0 for the root. The owner lays
out and paints what is marked outermost first, by depth.
no setter
- globalOffset → (int, int)
-
The column and row of this object's top left cell on the screen: its
offset and its ancestors' added up, as the last layout placed them.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- height ↔ int
-
How many rows this object takes, set by its performLayout within
the constraints it was given.
getter/setter pair
- hitTestBehavior → HitTestBehavior
-
What a hit test does with this object (hitTest): any object is
HitTestBehavior.opaque unless it says otherwise, as one that paints
all of its cells is; one with children (RenderObjectWithChildMixin,
ContainerRenderObjectMixin) defers to them unless it paints its own
cells too.
no setter
- isRepaintBoundary → bool
-
Whether this object is a repaint boundary, repainted on its own over
what it painted before when something inside it is marked
(markNeedsPaint); false by default.
no setter
- keepsUnderlay → bool
-
Whether this repaint boundary paints over what is under it, with no
background of its own: a field, a gauge over a dialog, a selected
row, a gradient; false by default.
no setter
- owner ↔ PipelineOwner?
-
The pipeline this object is attached to (attach); null while it is
detached, when nothing in it is laid out or painted.
getter/setter pair
- paintedWhenCutOff ↔ bool
-
Whether this object is painted even where the clip of its parent
leaves none of it, and so are the objects above it: its paint does
more than paint its cells (it shows the terminal's cursor, or hides
it), which has to happen however it is cut off. Its cells are not
painted then: the clip it paints in is empty. Off by default: a child
the clip leaves no cell of is not painted, nor anything inside it
(paintChild).
getter/setter pair
- parent ↔ RenderObject?
-
The object this one is a child of; set by the parent (adopt,
drop).
getter/setter pair
- parentData ↔ ParentData
-
What the parent keeps on this object: its offset and whatever else
the parent's layout needs. Set up by the parent when it adopts this
object (setupParentData) and filled in by the parent's layout.
getter/setter pair
- putsUnderlayBack → bool
-
Whether the owner puts back the underlay of the rows this boundary
repaints on its own, before it repaints them (keepsUnderlay); true
by default. False for one that keeps cells it does not repaint,
which puts it back itself (putUnderlayBack).
no setter
- repaintedWhole ↔ bool
-
Whether all of this object is repainted whenever a repaint boundary
it is in repaints any of its rows: what it paints depends on more
than itself and what is inside it (where another object is now), so
a change elsewhere in the boundary may change it without marking it.
Off by default: a boundary repaints only the rows of the objects
marked for paint in it (markNeedsPaint).
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sizedByParent → bool
-
Whether this object's size depends on its constraints alone; false by
default. Whatever changes inside it, its parent sees the same size,
so the object is a relayout boundary. Read in layout once
constraints are the new ones, so it may depend on them.
no setter
- underlayRowsAlike → bool
-
Whether every row of the underlay of this boundary is the same
(keepsUnderlay): rows of it moved up or down on the surface then
show over what is under their new place; false where its parent has
not painted all of it since it moved, or keeps none.
no setter
- width ↔ int
-
How many columns this object takes, set by its performLayout within
the constraints it was given.
getter/setter pair
Methods
-
adopt(
RenderObject child) → void -
Makes
child, which has no parent, a child of this object: gives it parentData (setupParentData), attaches it to this object's owner, if any, and lays this object out again. The parent's own list of children holds it too (RenderObjectWithChildMixin.child, ContainerRenderObjectMixin.insert). -
attach(
PipelineOwner o) → void -
Joins the pipeline of
o, with everything inside it: the owner lays out and paints what is marked in it. A relayout boundary marked while detached is laid out on the next frame, and the intrinsic sizes worked out before are forgotten, sinceomeasures text with its own segmenter. The parent attaches what it adopts (adopt), and the owner its root (PipelineOwner.root). -
beforePaint(
) → void - Called, while this object is checkedBeforePaint, by each PipelineOwner.flushPaint that has anything to paint: after layout, before the flush settles the rows its boundaries repaint. What it marks for paint here (markNeedsPaint) that flush paints. One that paints by where other objects are, which may move in another repaint boundary without marking it, marks itself here when they moved: in the same frame. What it throws, it shows, marked for paint.
-
computeMaxIntrinsicHeight(
int width) → int - What getMaxIntrinsicHeight answers; see computeMinIntrinsicWidth.
-
computeMaxIntrinsicWidth(
int height) → int - What getMaxIntrinsicWidth answers; see computeMinIntrinsicWidth.
-
computeMinIntrinsicHeight(
int width) → int - What getMinIntrinsicHeight answers; see computeMinIntrinsicWidth.
-
computeMinIntrinsicWidth(
int height) → int -
What getMinIntrinsicWidth answers, worked out without laying
anything out. A container asks its children through their
getmethods, so their answers are cached too; text is measured with the owner's PipelineOwner.segmenter, as the canvas draws it. An object asks for nothing (0) unless it overrides these. -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Adds what describes this object, besides its type, size and flags, to
properties, those not worth showing (a default) left out; an override calls this first. Only describe calls it: a frame never does. -
describe(
) → DiagnosticsNode -
This object and those below it as a tree of descriptions, built when
called: its type; the properties debugFillProperties adds, those its
parent keeps on it (ParentData.debugFillProperties), its offset in
the parent and the constraints of its last layout (
tight, or what describeConstraints says); the error it shows in its place, if any (debugError); its size once laid out; and as flags whether it is a repaint boundary, a relayout boundary, to be laid out, to be repainted or showing an error. -
detach(
) → void - Leaves the pipeline: nothing in this subtree is painted until it is attached again.
-
drop(
RenderObject child) → void -
Removes
childfrom this object (the parent's own list of children must no longer hold it): it is detached from the pipeline, and this object is laid out and repainted without it. -
getMaxIntrinsicHeight(
int width) → int -
The height beyond which this object has no use for more at
width. -
getMaxIntrinsicWidth(
int height) → int -
The width beyond which this object has no use for more at
height(for text, its widest line unbroken). -
getMinIntrinsicHeight(
int width) → int -
The fewest rows this object can have at
widthwithout cutting its content off. -
getMinIntrinsicWidth(
int height) → int -
The narrowest this object can be at
heightwithout cutting its content off (for text, the widest piece no line break can split). What a parent asks before laying the object out; answered once per argument until markNeedsLayout (see computeMinIntrinsicWidth). -
hitTest(
HitTestResult result, int x, int y) → bool -
Adds what is at
x,yof this object, a cell in its own coordinates, toresult: nothing when the cell is outside its bounds (a child that sticks out of its parent is cut off there, as paint cuts it); otherwise the children hit there (hitTestChildren), then this object when it is hit there itself (hitTestSelf), a child is, or it is HitTestBehavior.translucent. Returns whether it is hit: then what it covers is not tested. An object that shows an error (debugError) is hit anywhere in its bounds, and its children not tested. Uses the last layout; allocates nothing. -
hitTestChildren(
HitTestResult result, int x, int y) → bool -
Hit tests the children at
x,yof this object, each in its own coordinates, the one painted last (on top) first, until one is hit; returns whether one was. Nothing by default. -
hitTestSelf(
int x, int y) → bool -
Whether this object is hit at
x,yof its own, a cell in its bounds, where no child is: when it is HitTestBehavior.opaque. One that paints only some of its cells may answer for each. -
invalidatePaintCache(
) → void - Forgets what this object kept of what it painted before, to paint from that: its cells were, or will be, painted over by an ancestor, or an object inside it was marked for paint (markNeedsPaint). Nothing by default.
-
invokeLayoutCallback(
void callback()) → void -
Runs
callbackin this object's performLayout, before it lays its children out: the callback may adopt, replace and drop children of this object and of those below it (a widget layer builds them there). The marks that makes stop at this object, which is being laid out, or at relayout boundaries, which the owner lays out after it in the same flush (PipelineOwner.flushLayout): what changed is laid out before anything is painted. When an intrinsic size this object answered before comes out different afterwards, its parent may have laid it out by the old one: the parent is laid out again on the next frame, or the object itself when it is the root (whose owner's frame may size an inline region by it). -
layout(
BoxConstraints c, {bool parentUsesSize = false}) → void -
Lays this object out within
c. A parent whose layout reads this object's size passesparentUsesSize. Otherwise, or whencis tight or the object is sizedByParent, its size can't change the parent's layout: the object is a relayout boundary, where markNeedsLayout inside it stops. -
markNeedsLayout(
) → void - Lays this object out on the next frame, with the ancestors whose layout uses its size: the mark climbs to the nearest relayout boundary, and the owner lays that boundary's subtree out. Forgets the intrinsic sizes worked out so far; when any was asked for, the parent is marked too, boundary or not, since its layout may have used them.
-
markNeedsPaint(
) → void - Repaints this object on the next frame, with the nearest repaint boundary at or above it; a boundary above it forgets what it painted before (invalidatePaintCache). Of that boundary only the rows this object covers then are repainted, all of them across: what its ancestors paint there, then what is inside them there, in order. A boundary marked itself repaints all of it.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
paint(
PaintContext ctx) → void - Paints this object at the canvas origin, the canvas clipped to its bounds, and its children with paintChild. What this throws, the object shows in its place (see RenderObject).
-
paintChild(
PaintContext ctx, RenderObject child) → void -
Paints
childat its offset, cut off at its bounds. A child the clip leaves no cell of is not painted, nor anything inside it, unless something inside it is paintedWhenCutOff; one not painted keeps what it kept of its paint, since its cells are as it left them. -
paintOver(
PaintContext ctx, RenderObject child, int x, int y, int w, int h) → void -
Paints again what this object paints over
childin the cellsx,y,w×hof its own (paintsOver), which a repaint boundary insidechildhas just repainted on its own, over whatever covered it there. The canvas is clipped to those cells, its origin at this object. -
paintsOver(
RenderObject child, int x, int y, int w, int h) → bool -
Whether this object paints anything over
childin the cellsx,y,w×hof its own. Not by default: only children that overlap paint over each other (RenderStack). -
performLayout(
BoxConstraints c) → void -
Sets width and height within
c, laying out and placing the children first; layout calls it, when the constraints are new or the object was marked (markNeedsLayout). -
putUnderlayBack(
Canvas canvas, int x, int y, int w, int h) → void -
Puts back the styles of the cells under this boundary
(keepsUnderlay) in its rectangle at
x,yofw×hcells (in its own coordinates, within the clip ofcanvas): what it then paints there is over what its parent left. A cell its parent has not painted since it moved is left as it is. For a boundary that puts it back itself (putsUnderlayBack false), before it paints the cells. -
setupParentData(
RenderObject child) → void -
Gives
child, about to be adopted, the kind of parentData this object's layout keeps on it. A container that keeps more than the offset replaces data of any other kind. -
toString(
) → String -
A string representation of this object.
inherited
-
visitChildren(
void visit(RenderObject child)) → void -
Calls
visitwith each child of this object, in paint order; none by default. An object with children overrides it, which the pipeline walks the tree by (attach, detach, describe). -
wholeRows(
Int32List rows) → void -
Which of its rows this object, repaintedWhole, has repainted with a
repaint boundary it is in that repaints any rows:
rowsholds 0 and its height when asked, and is left holding the first of them, in its own coordinates, and the row after the last; none when the first is not before the other. All of them unless it says otherwise: one that paints by where other objects are may answer the rows it showed in last joined with those it shows in now, and none when they are the same. Asked as a flushPaint settles the rows its boundaries repaint, after layout and before anything is painted, once for each boundary around it that repaints any rows: the same answer every time in one flush.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited