flutterdartformatting

Why are trailing commas auto deleted and not formatted in flutter?


The trailing commas used to be auto formatted now does not format it but instead it deletes them. The same happens in Android Studio. What might cause this? This is the dart settings:

"[dart]": {
    "editor.formatOnSave": true,
    "editor.formatOnType": true,
    "editor.selectionHighlight": false,
    "editor.tabCompletion": "onlySnippets",
    "editor.wordBasedSuggestions": "off"
},

I tried reinstalling dart extension but same problem. The extension is what caused it but I do not know how to fix this.

Dart Version:
Dart SDK version: 3.7.0-259.0.dev

Dart-Code Extension Version: 3.102.0


Solution

  • Open your pubspec.yaml file and replace:

    environment:
      sdk: ^3.7.0
    

    with

    environment:
      sdk: ">=3.6.0 <4.0.0"
    

    This change adds backward compatibility for code formatting, making it work like in older versions. The reasoning behind the new formatting is unclear, but it feels extremely uncomfortable to use.