RepaintBoundary placement for a Flutter list with animated tiles: how many layers is too many
0 reputation · 28 Apr 2025, 01:30 UTC
0 reputation · 28 Apr 2025, 01:30 UTC
I have a Flutter screen where a mostly static list contains a few tiles that animate frequently (progress indicators and a chart that redraws on new data). The documentation describes RepaintBoundary as a way to isolate a subtree into its own layer so repaints do not propagate to the rest of the tree, which sounds like a fit for these tiles.
What is unclear is the practical limit. The framework docs and performance guidance warn that each boundary allocates its own layer and backing store, so wrapping every item in a long ListView.builder could increase memory usage and raster cost instead of reducing it. I also understand the framework already inserts boundaries in some widgets, so manual ones may be redundant.
Assume a recent stable Flutter 3.x release on Android and iOS. Verification would use the Repaint Rainbow flag and the raster thread timings in DevTools.
My questions:
RepaintBoundary, beyond "frequently changing content next to static content"?32275 reputation · 28 Apr 2025, 13:27 UTC
For a mostly static ListView with only a few tiles that animate each frame, the practical limit is “as few boundaries as you actually need”. In Flutter 3.x each RepaintBoundary creates its own composited layer and GPU backing store, so adding one per visible item quickly outweighs the repaint‑saving benefit.
RepaintBoundary isolates its subtree into a separate layer; repaints inside do not dirty ancestors.ListView.builder item scrolls off‑screen and its render object is disposed (default addAutomaticKeepAlives behavior), the layer and its backing store are released.RepaintBoundary – do **not** wrap the whole list item or the static surrounding content.debugRepaintRainbowEnabled (or the Repaint Rainbow toggle), run the animation, and confirm that only the wrapped tiles flash while the rest of the list stays static. Then compare the raster thread frame time before and after adding the boundaries; a flat or decreasing raster time indicates a net win.RepaintBoundary that currently wraps entire list items.RepaintBoundary(child: ProgressIndicator(...))).Ask for one missing diagnostic detail only when it changes the recommendation: if you are targeting a device with very limited GPU memory (e.g., low‑end Android 512 MB RAM), let me know the exact memory budget so we can adjust the safe number of boundaries.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.