Dart-code: extension 'flutter' cannot format '.dart'

Created on 15 Mar 2020  路  5Comments  路  Source: Dart-Code/Dart-Code

灞忓箷蹇収 2020-03-15 13 14 09

Environment

  • vscode: 1.43.0
  • flutter extension: 3.8.1
  • dart extension: 3.8.1
  • settings.json
{
  "editor.fontSize": 13.5,
  "editor.fontFamily": "Fira Code",
  "editor.fontLigatures": true,
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "Dart-Code.flutter"
}

Expectation

灞忓箷蹇収 2020-03-15 13 17 39

is question

Most helpful comment

"editor.defaultFormatter": "Dart-Code.flutter"

The formatter for Dart is in the Dart extension (since it should work for non-Flutter users too), so if you're setting the formatter explicitly for Dart you should set it to Dart-Code.dart-code.

That said, this formatter can *only format Dart, so you shouldn't set it as the default formatter for all lanuguages, as it will prevent you from being able to format other languages.

Unless you have good reason, you should be able to just delete that line from your settings - VS Code will use the Dart formatter for Dart files automatically without any specific configuration.

Let me know if this doesn't seem to work for you. Thanks!

All 5 comments

"editor.defaultFormatter": "Dart-Code.flutter"

The formatter for Dart is in the Dart extension (since it should work for non-Flutter users too), so if you're setting the formatter explicitly for Dart you should set it to Dart-Code.dart-code.

That said, this formatter can *only format Dart, so you shouldn't set it as the default formatter for all lanuguages, as it will prevent you from being able to format other languages.

Unless you have good reason, you should be able to just delete that line from your settings - VS Code will use the Dart formatter for Dart files automatically without any specific configuration.

Let me know if this doesn't seem to work for you. Thanks!

@DanTup Thanks for the reply! But It doesn't work for me.

@DanTup I figured it out. I should add , after LinearGradient()!

Sorry, it seems like there were two issues described and I only covered the first. The initial error saying Flutter can't format was for the reason I gave above. Trailing commas are the correct way to force the specific formatting you wanted - there's a little more info about this on the Flutter website here:

https://flutter.dev/docs/development/tools/formatting#using-trailing-commas

"editor.defaultFormatter": "Dart-Code.flutter"

The formatter for Dart is in the Dart extension (since it should work for non-Flutter users too), so if you're setting the formatter explicitly for Dart you should set it to Dart-Code.dart-code.

That said, this formatter can *only format Dart, so you shouldn't set it as the default formatter for all lanuguages, as it will prevent you from being able to format other languages.

Unless you have good reason, you should be able to just delete that line from your settings - VS Code will use the Dart formatter for Dart files automatically without any specific configuration.

Let me know if this doesn't seem to work for you. Thanks!

Thank You, this is working for me now!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shamrin picture shamrin  路  5Comments

mccadi picture mccadi  路  3Comments

e200 picture e200  路  3Comments

atreeon picture atreeon  路  5Comments

FeimiSzy picture FeimiSzy  路  4Comments