What is RepaintBoundary and when should you use it?

Why Interviewers Ask This

This is a differentiating question used for senior and lead roles. Interviewers want to see if you can explain not just what happens, but why — and what the trade-offs are in different approaches.

Answer

RepaintBoundary promotes its child widget to its own compositing layer. When only the child changes, Flutter can repaint just that layer and composite it with the other unchanged layers, without repainting the rest of the screen. Use it around widgets that repaint frequently but are visually isolated — like a custom animated widget, a video player, or a rapidly updating progress indicator. The tradeoff is extra memory for the additional layer. You can verify if your RepaintBoundary is helping by enabling the "Show repaint rainbow" in DevTools.

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Flutter codebase.