Skip to content

extension 'flutter' cannot format '.dart' #2300

@Liqiankun

Description

@Liqiankun

屏幕快照 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

Activity

DanTup

DanTup commented on Mar 15, 2020

@DanTup
Member

"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!

Liqiankun

Liqiankun commented on Mar 15, 2020

@Liqiankun
Author

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

Liqiankun

Liqiankun commented on Mar 15, 2020

@Liqiankun
Author

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

DanTup

DanTup commented on Mar 17, 2020

@DanTup
Member

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

vaibhavcs99

vaibhavcs99 commented on Dec 16, 2020

@vaibhavcs99

"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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @DanTup@Liqiankun@vaibhavcs99

        Issue actions

          extension 'flutter' cannot format '.dart' · Issue #2300 · Dart-Code/Dart-Code