29

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),
2
  • 13
    you should add a , after brightness: Brightness.light. Commented Jul 14, 2020 at 7:06
  • 2
    wow that changed my life ngl Commented Mar 10, 2022 at 1:58

7 Answers 7

42

config file .vscode/settings.json

{
    "editor.formatOnSave": false,
    "[dart]": {
        "editor.formatOnSave": false
    }
}
2
  • 1
    So there we find this .vscode/settings.json?
    – nww04
    Commented May 18, 2021 at 6:28
  • 1
    @NeonWarge - In the root of your project folder, create a folder named ".vscode" with a file named "settings.json", and add the configuration above. Vscode also does this for you, if you make changes to settings from the editor. Commented May 26, 2021 at 19:53
18

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

enter image description here

15

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.

13

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!

2
  • this worked great, but I was hoping to find a comment I could place at the top of the file to avoid formatting on this file ubiquitously. do you know if that exists?
    – MetaStack
    Commented Oct 17, 2022 at 18:06
  • this worked great, need a place to top
    – ziqq
    Commented Jan 13, 2023 at 13:37
11

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,
        ...
    }
}

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.

1

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.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.