In Android studio, when I open a dart file, I see two options to format the code, so my question is
What is the difference between Reformat Code / Reformat Code with dartfmt
In Android studio, when I open a dart file, I see two options to format the code, so my question is
What is the difference between Reformat Code / Reformat Code with dartfmt
Difference between them I don't know but I know how you can add a shortcut to format code: Go to
File -> Settings -> Keymap -> Editor Action -> Reformate Code with dartfmt
and add click on it and add a shortcut
Both are the same essentially.
The only difference is that Reformat Code (ctrl + alt + L)
applies only to the file open in the Editor or the file selected in project files pane using Intellij
's Code formatter feature.
While Reformat Code using dartfmt
uses dartfmt
CLI command available with the flutter
SDK.
The output of both will be the same. dartfmt
allow you to format the code on directory level and from a cmd/terminal instead of an IDE.
**Automatically formatting code in Android Studio and IntelliJ ** Install the Dart plugin to get automatic formatting of code in Android Studio and IntelliJ.
To automatically format the code in the current source code window, right-click in the code window and select Reformat Code with dartfmt. You can add a keyboard shortcut to this in Keymap section of IntelliJ Preferences.
You can also do it with
flutter format path1 path2 ... (From terminal window)
Official link to flutter formatting tool This shows that dartfmt is just a formatter by dart specifically for dart files. Default format code given by Android studio also could do this if file extension is identified by Android studio.
© 2022 - 2024 — McMap. All rights reserved.
ctrl + alt + L
. But if you havent added comma(,
) correctly in your widget tree. It will act weird. – Doner