flutterdartvisual-studio-codeindentation

Configure Dart indentation in VS Code


I’m using VS Code to code in Dart (for Flutter). The default indentation is 2 spaces, but I want tabs instead of spaces. I’ve set tabs (with tab size 4) in several places, but without success.

https://i.sstatic.net/1zfNg3Lo.png

https://i.sstatic.net/AgOynS8J.png

https://i.sstatic.net/7oB0HCEe.png

Even at the bottom right, I can see “Tab 4” for each document.

Even with shortcut Alt + Shift + F nothing.

Thank you.


Solution

  • I also prefer to use 2 spaces for indentation, and I have no problem with it. I believe it's a crucial standard because Dart can be quite verbose, especially if your code is not properly organized.

    For better readability, I find that 2 spaces work better than 4 (a single tab), and you'll see the difference if you've already read thousands of lines of code written in Dart, particularly if it has many child widgets, ternary operators, etc.

    In addition, I also notice that it automatically adds linebreaks and indents 4 spaces if a single but lengthy line of code is separated by white spaces or commas, etc.

    My advice is to stick to having 2 spaces as its default indentation if it's pure Dart code, or in simple terms, leave as is. I suspect that you're concerned about readability, but leaving its default indentation out of the box is much more appropriate for me.