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

You need to change 2 settings in settings.json:

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

If you do not change the second one, you'll still see the vertical "ruler" at 80 chars width.


It seems like you are hitting line length limit.

Default maximum line length is classic 80 characters, so for your code you would need a lot of padding to hit the limit so formatter would break the line. If this is an issue - consider splitting your code.

This is properly formatted:

class MyApp {
  void insideclass() {
    if (true) {
      if (true) {
        if (true) {
          if (true) {
            if (true) {
              if (true) {
                if (true) {
                  if (true) {
                    var tuple =
                        settings.arguments as Tuple3<String, int, Field>;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

class MyApp2 {
  void insideclass() {
    if (true) {
      if (true) {
        if (true) {
          if (true) {
            if (true) {
              if (true) {
                if (true) {
                  var tuple = settings.arguments as Tuple3<String, int, Field>;
                }
              }
            }
          }
        }
      }
    }
  }
}

However if 80 is actually too small for you, you can also change that in VSCode in the extension's settings.

VSCode Dart&Flutter extension settings - line length