简体   繁体   中英

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

在此处输入图片说明

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM