audo add const keyword in flutter code

Hi Guys: Welcome to Proto Coders Point, welcome. If you recently updated your flutter SDK to version 2.5.0 or higher, you might have noticed that every widget that uses static data now displays a warning to include the “const” modifier at the beginning of the widget.

This is due to the fact that the flutter lints rules are now automatically applied.

Video tutorial to automatically add const keyword everywhere in code

Using the const keyword on any data type or widget that uses static data is a recommended practise.


How to auto add const keyword in flutter code

However, you may update your analysis_options.yaml file and include the following if you’d like to auto add const in your code:

In you flutter project structure:

Step 1: open analysis_option.yaml file & under linter > rules disable prefer_const_constructor:

Step 2: Add prefer const constructors and make it false

linter:
  rules:
    prefer_const_constructors : false   //add this line

Step 3: Run dart fix apply in IDE terminal

After setting prefer_const_constructors to false, you must enter the following command into the IDE terminal.

dart fix --apply

This will auto add const keyword in your flutter code by analyzing your complete code

auto add const keywords in flutter code