Start a team blog
NEW โœจ
Start a team blog, invite your team, and start publishing.
Fix Flutter const with const constructors

Fix Flutter const with const constructors

Mobile Development with Google Flutter Framework

Petrus Nauyoma's photo
Petrus Nauyoma
ยทJan 24, 2022ยท

1 min read

So you are busy hammering away at your Dart code but, you keep seeing these squiggly lines: alt 'squiggly blue lines on code'

The problems terminal in Visual Studio Code might be showing this alt 'Prefer const with constant constructors.' To fix it, open the analysis_options.yaml which contains the linter rules. Add this line after the rules prefer_const_constructors: false

Your final lint rule should look like this:



    prefer_const_constructors: false

Solution view

run the command dart fix --apply in the terminal

alt 'dart fix doing it's job' and voila alt 'linting issue fixed'

What is the purpose of linting?

Linting defines the rules on how your code will be structured. These include rules like whether to use double quotes or single quotes or the spacing required after elements. My first encounter with it was working with Tailwind.css on a node.js tutorial. It is a pain in the neck! Hopefully, if you encounter this, now you have the solution. ๐Ÿ˜Š

Take Note!

You might have situations where you need to prefer const constructors. It saves up memory allocation which in turn means better performance (in the longer run). A great explanation is provided on StackOverflow in detail.