fluttervisual-studio-codeformatautoformatting

Flutter Auto Formatting on VSCode


Recently I got super annoyed with flutter (on VSCode) auto-formatting my file whenever I add a semicolon in the file for some reason...

Does anyone know how to stop this from happening? The auto formatting looks horrible and makes my code very hard to read

I tried to click on "Dart" at the bottom right of VS Code then go to edit Flutter based settings, and turned formatOnSave to false, but that did not work


Solution

  • You can completely disable the Dart formatter with "Dart: Enable Sdk Formatter" setting. This will unregister the formatter entirely, so it doesn't show up in the context menu, or fire for formatOnSave, formatOnPaste or formatOnType.

    Alternatively, if you want to be able to invoke the formatter manually (using the context menu or shortcut keys) but never have it run automatically, you can disable the automatic running by adding this to your VS Code user settings:

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

    It's possible you already have these defined if you accepted the Recommended Settings on first run, in which case just change them from true to false.