Search code examples
flutterdartvisual-studio-codeformattingcoding-style

how to change dart line length in vscode when formatting dart files?


i'm using VS Code for flutter development and one issue i have is code formatting (styling) which is not as customizable as it is in android-studio. my problem is that each time vs code saves dart files it will break my lines very short like below:

var tuple =
       settings.arguments as Tuple3<String, int, Field>;

obviously this is what i want :

var tuple = settings.arguments as Tuple3<String, int, Field>;

how can i solve this problem?


Solution

  • To change the line length in VSCode

    open settings.json and add the following lines

    "dart.lineLength": 120,
    "[dart]": {
        "editor.rulers": [
            120
        ],
    }
    

    SIDE NOTE: if you wish to change the dart line length for a single project that you have in VSCode create a .vscode/settings.json file and add configuration written above in that file.

    to change dart line length in Android Studio go to

    Settings > Editor > Code Style > Dart and change line length

    enter image description here