2

Previously, VS Code would automatically show the warning:

Try adding the 'const' keyword to the constructor invocation

However, now it only appears if I explicitly add

prefer_const_constructors: true

in my analysis_options.yaml.

I want VS Code to show this warning automatically without needing to enable the rule manually in every project.

Flutter Version : 3.29.0 
Dart Version : 3.7.0
0

2 Answers 2

4

That has been removed by default check this issue https://github.com/dart-lang/core/issues/833 along with other lints like avoid_print which was enabled in flutter lints by default.

The following lints were removed in flutter_lints: 5.0.0

  • prefer_const_constructors
  • prefer_const_literals_to_create_immutables
  • prefer_const_declarations

in this PR https://github.com/flutter/flutter/pull/156011

enter image description here

if you want to enable that again add this in analysis_options.yaml

linter:
  rules:
    prefer_const_constructors: true

or you can use version lesser than 5.0.0 like flutter_lints: ^4.0.0

Sign up to request clarification or add additional context in comments.

Comments

1

The const lint has been removed from flutter lints. You could check this issue https://github.com/dart-lang/core/issues/833 and https://github.com/flutter/flutter/issues/149932 or more details.

Right now, you would need to enable this lint rule in your `analysis_options.yaml` if you need it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.