7

I find it incredibly distracting to code with 2 spaces indentation, so I always set my indentation size to 4 spaces, however, on this flutter project, the indentation stays at 2 spaces, no matter what I change, it refuses to be 4 spaces... (this applies to all files, not just the main.dart file)

Example of spaces in my code

I've tried setting indentation spaces to 4 from 2 (https://stackoverflow.com/a/37077167/15586166 and https://stackoverflow.com/a/51398290/15586166) but even when it is set to 4 spaces for Dart specific projects (the json file), workspace settings (assuming frontend for json file) and in the VSCode user settings tab, it goes back to 2 spaces on format (or rather the settings stays at 4 spaces, but it still formats at 2 spaces). I do not have a .editorconfig, so I couldn't change it there. I've also disabled detect indentations (https://stackoverflow.com/a/43809036/15586166) on all the levels I did with the indentations sizes.

JSON settings

User settings

VSCode spaces display preview

Could it be that dart_style (which I am assuming is formatting the code), enforces 2 spaces indentations? If it is, is it possible to change it?

dart style enabled

Although, taking a look through its code, it shouldn't be enforcing 2 spaces, like this function. (see image)

Code Snippet

I also only have these 2 extensions for Dart/Flutter, and only Prettier formatter (only other formatter), but disabling it does not fix the issue...

Extensions

6
  • Tbh with how flutter is structured it's better to use 2 spaces. Commented Nov 17, 2022 at 18:28
  • @LacticWhale Yeah, I guess, if I can't change it, then I'll make do, it's not the end of the world, just an annoyance Commented Nov 18, 2022 at 4:37
  • 1
    it also annoyed hell out of me XD. But later I noticed how "hilly" flutter code is. Commented Nov 18, 2022 at 6:12
  • 4
    I fail to see "with how flutter is structured it's better to use 2 spaces". How does indenting with 4 spaces make one iota of difference to the language? I just started looking at Flutter but forcing me to not see the code indentation clearly enough is going to make life a living hell. Commented Apr 2, 2023 at 2:00
  • I am surprised tabs aren't used. At least with a tab, people can choose how much space a tab takes, 2, 4, 8. Whitespace is important. It is exhausting reading Flutter. After a while, all the code just looks the same "WidgetFormchildchildrenconstContainer". I imagine Flutter is very difficult on people with vision impairments. Commented Jan 6, 2024 at 11:28

1 Answer 1

5

For those who tired to wait a customisation from Dart guys here is a solution: fork the dart_style repository, change to own needs and setup the replacement to be used in VSCode. Instruction (and ready patch) is here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.