Skip to content

Remove the annoying const lints from flutter_lints #843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
goderbauer opened this issue Sep 5, 2024 · 1 comment
Closed

Remove the annoying const lints from flutter_lints #843

goderbauer opened this issue Sep 5, 2024 · 1 comment

Comments

@goderbauer
Copy link
Contributor

In theory, const-ness should give apps a performance boost, but during development the lints enforcing const are constantly nagging developers: "Make this const" or "This cannot be const anymore". To evaluate whether we are making the right trade-offs here between annoyingness and performance we ran some benchmarks (see flutter/flutter#149932). The benchmarks have not shown sufficient evidence to suggest that there is a statistically significant difference in performance between const and nonconst for real world apps1. Given these results, the lints that constantly nag developers during development are not carrying their weight and I suggest we remove them from the flutter_lints set. People can still manually enable them for their app, if they like.

Lints suggested for removal from the flutter_lints set (they can still be enabled manually):

  • prefer_const_constructors
  • prefer_const_literals_to_create_immutables
  • prefer_const_declarations

I suggest we keep the forth const lint (prefer_const_constructors_in_immutables) because it is very narrow in scope and generally doesn't cause any pain during development. It also enables downstream consumers to make their own choice of whether they want to create a const instance of a widget or not.

Footnotes

  1. In a contrived benchmark that did not represent real world usage in Flutter apps we were able to show that const in general can give you a small performance advantage.

@mateusfccp
Copy link

@goderbauer Why was this issue closed? Did you find anything new that changes how we perceive e constness in Flutter?

delthas pushed a commit to irctoday/goguma that referenced this issue May 11, 2025
This has been dropped from the upstream "recommended" set [1]. Some
benchmarks haven't revealed sizable performance gains [2].

Let's just ignore it instead of fixing 294 warnings.

[1]: dart-lang/core#843
[2]: dart-lang/core#833
This issue was closed.
This issue is being transferred. Timeline may not be complete until it finishes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants