What does RepaintBoundary do and when should you use it?
Short Answer
RepaintBoundary isolates its child into a separate compositing layer, so repainting that subtree doesn't force everything around it to repaint too — useful for expensive-to-paint widgets that change independently, but overusing it wastes memory on unnecessary layers.
Normally, when part of the widget tree needs to repaint, Flutter may need to repaint more of the tree around it. Wrapping an expensive or frequently-changing widget (like a complex CustomPainter animation) in RepaintBoundary gives it its own GPU-composited layer, isolating its repaints from siblings and ancestors — genuinely helpful when you have one 'hot' widget in an otherwise static area of the screen.
The tradeoff is memory: each RepaintBoundary layer costs GPU memory to maintain, so wrapping everything speculatively actually hurts performance rather than helping.
Common Mistakes
- ×Sprinkling RepaintBoundary throughout the tree speculatively without profiling first.
- ×Not realizing Flutter already inserts implicit RepaintBoundaries in some cases — manually adding one may be redundant.