So i wanted to work on my app but suddenly when i save, the document autoformats. Yesterday i had no problems but now i have. I have checked by autoformatting but that is off. When i opened VS Code i got a message to set dart for default language or something like that, maybe that is the problem?

I want it this way:

      theme: ThemeData(
      backgroundColor: Colors.white70,
      primarySwatch: Colors.blue,
      brightness: Brightness.light
    ),

But i get it this way:

      theme: ThemeData(
      backgroundColor: Colors.white70,
      primarySwatch: Colors.blue,
      brightness: Brightness.light),


Solution 1: ARVOCI

I found the problem This should be on flutter. It was first null.

enter image description here


Solution 2: AyeAreEm

I am having the same problem that you have. I couldn't find a way to fix it but there is a way to save the code without formatting. On Windows, if you click Ctrl + K then Ctrl + Shift + S, it will save the file without formatting. I am not sure on Mac but if you go to command palette and search save without format, it will show you the shortcut to do it. Hope this helps!


Solution 3: xiebin

config file .vscode/settings.json

{
    "editor.formatOnSave": false,
    "[dart]": {
        "editor.formatOnSave": false
    }
}


Solution 4: اسماعیل زارع

This solution worked for me:

Go to the Setting -> Text Editor -> Formatting and on the Format On Save Mode choose the modifications and test.


Solution 5: José Pulido

I found another solution that worked like a charm. I've tried many other solutions but nothing. Just go to Settings and type dart: enable sdk formatter and turn it off. Quit and open VS Code to apply the changes.


Solution 6: Grand

This worked for me: Insert the following line into the settings.json file in the Dart language section:

"editor.defaultFormatter": "Dart-Code.dart-code",

The file should look like this:

"[dart]": {
    "editor.defaultFormatter": "Dart-Code.dart-code",
    "editor.formatOnSave": true,
    "editor.formatOnType": true,
},

You can keep the global VS Code Default Formatter unchanged (I use Prettier for working with other languages.) Just search for Default Formatter in Settings.

Note that there is also a setting for Dart-Code.flutter in the Default Formatter list. However, for some reason only Dart-Code.dart-code works!

You could change the global setting to Dart-Code.dart-code if you wish (and save having to mess with the settings.json file), however its cleaner just to add it to the file in the Dart section so you are not affecting your global formatter settings in VS Code.


Solution 7: David Gaspar

Access Manager (gear icon in lower left corner) -> Settings -> Open Settings (JSON) (top right corner) and then change these keys to true:

{
    ...
    "[dart]": {
        "editor.formatOnSave": false,
        "editor.formatOnType": false,
        ...
    }
}