DEV3 Technologies home

DEV3 Developer Forum

My Flutter list scrolls with jank. What are the first things to check?

Flutter helpSolved0 views
dev3 ·

A feed with images and cards drops frames when scrolling on a mid-range Android phone. I tested in debug mode. Where do I start measuring and what are the usual fixes?

#flutter#performance#listview

0

1 reply

dev3 · Accepted answer

Step 0: measure in profile mode

Debug mode is much slower and misleading. Run on a real device:

flutter run --profile

Open DevTools > Performance, enable the performance overlay and look for frames over 16 ms (60 Hz) in the UI or raster thread.

Usual fixes, in order of impact

  1. Build lazily. Use ListView.builder (or SliverList.builder), never ListView(children: items.map(...).toList()) for long lists. Give itemExtent or prototypeItem when rows have equal height, it speeds up layout.
  2. Resize images. Decoding a 4000 px photo for a 100 px thumbnail is the classic cause. Use Image.network(url, cacheWidth: 300) or serve thumbnails; cached_network_image adds disk caching.
  3. Use const. const widgets are skipped during rebuilds.
  4. Narrow rebuilds. Do not call setState high in the tree for a small change; extract widgets, use select (Provider/Riverpod) or ValueListenableBuilder.
  5. Do work outside build. No sorting, JSON parsing or filtering in build. Heavy parsing goes into compute()/Isolate.run() (Dart 2.19+).
  6. Avoid expensive effects in lists. Opacity, ClipRRect with anti-aliasing, big BoxShadows and saveLayer operations (see RepaintBoundary and the "highlight oversized images" and "raster cache" overlays) cost a lot per item.
  7. Add RepaintBoundary around parts that animate independently of the list.
ListView.builder(
  itemCount: posts.length,
  itemExtent: 96,
  itemBuilder: (_, i) => PostTile(key: ValueKey(posts[i].id), post: posts[i]),
)

Pitfalls

  • shrinkWrap: true on a long list disables laziness.
  • Shader compilation jank on first run is addressed by the Impeller renderer, now default on iOS and on current Android releases; check your Flutter version notes before using older workarounds.
  • Optimising without a profile usually fixes the wrong thing.
0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.