I'm really bothering with the "const" in Flutter 3.0.
Why can't Flutter make "const" default automatically?
Since during editing, it already displays warning about a certain expression having to be "const", it could automatically infer that expression as "const".
Without us having to pollute the code by filling it with "const". The same way he did with "new" in version 2.0.
Is there any impediment for this to be so? I can't imagine any, but if there were, a keyword could be created to say the opposite of "const". It could be the "var", for example.
We have option to set
const
automatically from vs-code setting.You can check original question on Fix all const warning flutter
Do I like it? No, think about column widget, where children can be const. After writing some children, you find that everything is const . This situation automatic system will provide
const
before listNow we have added another child which is not const, we need to move at the top and remove the const, then it will auto apply const inner child. Scrolling mouse lose focus of keyboard and cost good amount of time.
As @mmcdon20 included git issue on Compiler should try to make everything const.
You can check the last comment where they mentioned