To automatically format code whenever you save a file, set the
editor.formatOnSave setting to true.

Automatically formatting code in Android Studio and IntelliJ

Install the Dart plugin (see
Editor setup)
to get automatic formatting of code in Android Studio and IntelliJ.
To automatically format your code in the current source code window,
use Cmd+Alt+L (on Mac) or Ctrl+Alt+L (on Windows and Linux).
Android Studio and IntelliJ also provide a check box named
Format code on save on the Flutter page in Preferences
(on Mac) or Settings (on Windows and Linux)
which formats the current file automatically when you save it.

Automatically formatting code with the dart command

You can also automatically format code in the command line interface
(CLI) using the dart format command:

dart format path1 path2 ...

Using trailing commas