RepaintBoundary class

A widget that creates a separate display list for its child.

This widget creates a separate display list for its child, which can improve performance if the subtree repaints at different times than the surrounding parts of the tree.

This is useful since RenderObject.paint may be triggered even if its associated Widget instances did not change or rebuild. A RenderObject will repaint whenever any RenderObject that shares the same Layer is marked as being dirty and needing paint (see RenderObject.markNeedsPaint), such as when an ancestor scrolls or when an ancestor or descendant animates.

Containing RenderObject.paint to parts of the render subtree that are actually visually changing using RepaintBoundary explicitly or implicitly is therefore critical to minimizing redundant work and improving the app's performance.

When a RenderObject is flagged as needing to paint via RenderObject.markNeedsPaint, the nearest ancestor RenderObject with RenderObject.isRepaintBoundary, up to possibly the root of the application, is requested to repaint. That nearest ancestor's RenderObject.paint method will cause all of its descendant RenderObjects to repaint in the same layer.

RepaintBoundary is therefore used, both while propagating the markNeedsPaint flag up the render tree and while traversing down the render tree via PaintingContext.paintChild, to strategically contain repaints to the render subtree that visually changed for performance. This is done because the RepaintBoundary widget creates a RenderObject that always has a Layer, decoupling ancestor render objects from the descendant render objects.

RepaintBoundary has the further side-effect of possibly hinting to the engine that it should further optimize animation performance if the render subtree behind the RepaintBoundary is sufficiently complex and is static while the surrounding tree changes frequently. In those cases, the engine may choose to pay a one time cost of rasterizing and caching the pixel values of the subtree for faster future GPU re-rendering speed.

Several framework widgets insert RepaintBoundary widgets to mark natural separation points in applications. For instance, contents in Material Design drawers typically don't change while the drawer opens and closes, so repaints are automatically contained to regions inside or outside the drawer when using the Drawer widget during transitions.

See also:



RepaintBoundary({Key? key, Widget? child})
Creates a widget that isolates repaints.
RepaintBoundary.wrap(Widget child, int childIndex)
Wraps the given child in a RepaintBoundary.


child Widget?
The widget below this widget in the tree.
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
runtimeType Type
A representation of the runtime type of the object.
no setterinherited


createElement() SingleChildRenderObjectElement
RenderObjectWidgets always inflate to a RenderObjectElement subclass.
createRenderObject(BuildContext context) RenderRepaintBoundary
Creates an instance of the RenderObject class that this RenderObjectWidget represents, using the configuration described by this RenderObjectWidget.
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
didUnmountRenderObject(covariant RenderObject 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's createRenderObject.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
toString({DiagnosticLevel minLevel =}) String
A string representation of this object.
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
toStringShort() String
A short, textual description of this widget.
updateRenderObject(BuildContext context, covariant RenderObject renderObject) → void
Copies the configuration described by this RenderObjectWidget to the given RenderObject, which will be of the same type as returned by this object's createRenderObject.


operator ==(Object other) bool
The equality operator.

Static Methods

wrapAll(List<Widget> widgets) List<RepaintBoundary>
Wraps each of the given children in RepaintBoundarys.