'Android Studio Tab to Spacing in Flutter(Dart)

How can I change tab to space in Android Studio 4.0 ? enter image description here



Solution 1:[1]

Since Dart does not have language-specific settings in Android Studio. Change use tab character or not in Other File Types options, which is for all file types that aren't separately available for options.

Editor > Code Styles > Other File Types > Uncheck Use tab character.

Solution 2:[2]

You can change it by editing the configuration file.

I use Linux, mine was located at ~/.config/Google/AndroidStudio2021.1/codestyles/Default.xml

<codeStyleSettings language="Dart">
  <indentOptions>
    <option name="INDENT_SIZE" value="4" />
    <option name="TAB_SIZE" value="4" />
  </indentOptions>
</codeStyleSettings>

If there is already a section for Dart, just add indent options, or else add the whole snippet just after <code_scheme> or just before </code_scheme>.

For IntelliJ users config file locations are given here - https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs

Solution 3:[3]

If you are an Android Developer and cannot leave Android Studio, since it's your coding home, but can't let go of flutter either.

Changing tab size won't work through Default.xml in codestyles.

Use a different theme: Visual Studio 2019 Dark Theme (this auto adjusts indentation and makes code look exactly as of Visual Studio Code). To install theme - plugins -> search "Visual Studio 2019 Dark Theme"

OR

Use a different font: I prefer

Font : "Droid Sans Mono Slashed" or "Monospaced" (You can use any that works for spacing)

Font size: 18 , Line Height 1.4 // For 14 inch screens

Font size: 14 , Line Height 1.2 // For 15.6 inch screens or larger

enter image description here

OR

A combination of above looks beautiful.

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frenco
Solution 2 Anirudh
Solution 3 Vaibhav Aggarwal