Reputation: 101
I'm creating a Flutter app in android studio. Under Settings -> Editor -> Code Style -> Dart, I enabled "use tab character" and changed the tab size and indent to 4.
However, nothing seemed to have changed in the main.dart file, so I used Ctrl-Alt-Shift-L to reformat the code (even tried with "code cleanup" enabled), but it still uses two spaces to indent.
How do I make android studio use tab characters?
Upvotes: 4
Views: 7754
Reputation: 121
You can still change the tab indents by manually editing the configuration files of Android Studio.
Open the configuration folder for codestyles:
macOS
~/Library/Application Support/Google/AndroidStudioXXXX.X/codestyles
Windows
%AppData%\Google\AndroidStudioXXXX.X\codestyles
or%AppData%\Roaming\Google\AndroidStudioXXXX.X\codestyles
Linux
currently unknown sorry
Add a new section into the file your IDE is using. Mine is codestyles/Default.xml
.
Like this:
<code_scheme name="Default" version="173">
...
<codeStyleSettings language="Dart">
<option name="BRACE_STYLE" value="2" />
<option name="METHOD_BRACE_STYLE" value="2" />
<option name="ELSE_ON_NEW_LINE" value="true" />
<indentOptions>
<option name="INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
...
</code_scheme>
Upvotes: 6
Reputation: 61
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.
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
OR
A combination of above looks beautiful.
Upvotes: 0
Reputation: 33
Android Studio 2020.3 %AppData%\Roaming\Google\AndroidStudio2020.3\codestyles
Default.xml
I found the codestyles at the above location on a Windows 10 box. Find the Dart section of the file. Add the tab options you want.
<codeStyleSettings language="Dart">
<option name="RIGHT_MARGIN" value="1000" />
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
<option name="INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
Upvotes: 2
Reputation: 508
Remark for Android Studio 4: In Android Studio 3.6 and below, dartfmt could simply be disabled, as described by Astavie. Unfortunately, this function has been removed in Android Studio 4.
Upvotes: 1
Reputation: 101
I needed to disable Dartfmt under Settings -> Editor -> Code Style -> Dart
Upvotes: 0