Performance Tuning
Tips for making your Flutter app run smoothly.
- Use const constructors for widgets that don't change. This prevents them from being rebuilt unnecessarily.\n\n- For long lists, always use ListView.builder() or GridView.builder(). These build items lazily as they scroll into view.\n\n- Minimize the use of setState() on widgets high up in the widget tree. Keep state as local as possible.\n\n- Use Flutter DevTools to profile your app and identify performance bottlenecks.
Code Example
// Good: Builds list items on-demand
ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(items[index].title),
);
},
)
// Bad: Builds all items at once, even those off-screen
ListView(
children: items.map((item) => ListTile(
title: Text(item.title),
)).toList(),
)