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?
0
DEV3 Developer Forum
Every post is reviewed first. Usually reviewed within 24 hours.
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?
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
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.Image.network(url, cacheWidth: 300) or serve thumbnails; cached_network_image adds disk caching.const widgets are skipped during rebuilds.setState high in the tree for a small change; extract widgets, use select (Provider/Riverpod) or ValueListenableBuilder.build. Heavy parsing goes into compute()/Isolate.run() (Dart 2.19+).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.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.