Does using const in the widget tree improve performance?

It is a small performance improvement, but it can add up in larger apps or apps where the view is rebuilt often for example because of animations.
const reduces the required work for the Garbage Collector.

You can enable some linter rules in analysis_options.yaml that tell you when you should add const because it’s not inferred but would be possible like

  • http://dart-lang.github.io/linter/lints/prefer_const_constructors.html
  • http://dart-lang.github.io/linter/lints/prefer_const_declarations.html
  • http://dart-lang.github.io/linter/lints/prefer_const_literals_to_create_immutables.html

or that reminds you when you use const but it is inferred anyway

  • http://dart-lang.github.io/linter/lints/unnecessary_const.html

See also https://www.dartlang.org/guides/language/analysis-options

Leave a Comment

tech