user12021836
user12021836

Reputation:

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

enter image description here

Upvotes: 5

Views: 4974

Answers (3)

Stefan Morcodeanu
Stefan Morcodeanu

Reputation: 2158

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

Upvotes: 4

Harshvardhan Joshi
Harshvardhan Joshi

Reputation: 3193

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.

Upvotes: 3

Swapnil Nakade
Swapnil Nakade

Reputation: 860

**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.

Upvotes: 0

Related Questions