Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to auto-format flutter with vscode?

I was wondering if there is a library like Eslint for Flutter/Dart that will automatically insert semicolons and trailing commas when I save the file.

FLutter Version: 1.22.3 Dart Version: 2.10.3

like image 932
Fabio Dias Avatar asked Nov 03 '20 20:11

Fabio Dias


2 Answers

With VS Code version 1.53 ( I am sure previous have this too) you don't need to install any special extension. Just navigate to:

Preferences -> Settings -> Text Editor -> Formatting

make sure "Format on save" is enabled

enter image description here

with every time you hit Ctrl + S your file will be saved as well as code formatted.

like image 107
Msmkt Avatar answered Oct 26 '22 04:10

Msmkt


  1. install the flutter extension.
  2. append or modify these lines in the settings.json file:
"[dart]": {
    "editor.defaultFormatter": "Dart-Code.dart-code",
    "editor.formatOnSave": true,
}

after this, you can format your dart file with the save (ctrl+s) action.

like image 23
Zchary Avatar answered Oct 26 '22 02:10

Zchary