D
Widget TreeEasy20 XP2 min read

How do const constructors improve Flutter performance?

TL;DR: Const widgets are canonicalized at compile time — Flutter skips rebuilding them entirely because it knows they cannot change. This is one of the easiest performance wins in Flutter.

Full Answer

When you mark a widget const, Dart creates a single compile-time constant. Flutter checks the element tree and, finding the widget pointer identical, skips the build phase entirely for that subtree.

This is especially powerful for static UI regions that sit inside frequently-rebuilding parents.

🎯

Enable the prefer_const_constructors and prefer_const_literals_to_create_immutables lint rules in analysis_options.yaml to get IDE warnings whenever you miss a const opportunity.

Code Examples

dartconst vs non-const rebuild behavior
Output
Only 'Count: $count' Text rebuilds on each setState call; the const Text widgets are skipped

Common Mistakes

  • Using const only on leaf widgets — also use it on subtrees like const Padding(padding: EdgeInsets.all(8))
  • Thinking const means the same as final — const is compile-time; final is runtime

Interview Tip

💡

Mention that the Flutter team measured const widgets reducing rebuild times significantly in large apps. It signals you care about production-quality code.

#const#performance#rebuild#compile-time