Emirhan Selim Uzun
Emirhan Selim Uzun

Reputation: 1120

How can I auto add 'const' in Flutter in Visual Studio Code?

In Visual Studio Code, how can you automatically add const when you press (Ctrl + S)?

Upvotes: 13

Views: 16812

Answers (4)

Vikash Kushwah
Vikash Kushwah

Reputation: 31

"editor.codeActionsOnSave": {
  "source.fixAll": true
}

gives error = Incorrect type. Expected "string".

so, use this

 "editor.codeActionsOnSave": {
            "source.fixAll": "explicit"
}

Upvotes: 3

krishnaacharyaa
krishnaacharyaa

Reputation: 25070

  • Press Ctrl + Shift + P
  • Search settings.json
    • Open the User Settings(Json)

      Enter image description here

    • Add the following code

       "editor.codeActionsOnSave": {
        "source.fixAll": true
      }
      
      

Note: It is a simplified and updated version of Emirhan's answer with required changes

Upvotes: 8

Noah0420
Noah0420

Reputation: 51

If there are things like constants or changes that can be improved, I recommend you apply for the same Flutter recommendations. Run this in your terminal and that's it.

Flutter fix

dart fix --apply

Upvotes: 5

Emirhan Selim Uzun
Emirhan Selim Uzun

Reputation: 1120

To add an auto const feature when you save the file in Flutter in Visual Studio Code, you should follow these steps:

  1. Press (Ctrl + P) then search for (settings.json) file.

  2. Add this code line to there;

     "editor.codeActionsOnSave": {
         "source.fixAll": true
     }
    

Upvotes: 29

Related Questions