Android Studio wrong auto indent for dart
Asked Answered
C

1

5

I am a newbie to Flutter and I am happy to try this great technology. And I am going to try to follow this example https://medium.com/flutterpub/flutter-auth-with-google-f3c3aa0d0ccc to do a Google Sign in

Personally, I like to separate the chains of function call line by line instead of one line. It is like below:

  _googleSignIn
        .signInSilently()
        .whenComplete(() => {
        print("Login complete");
  });

However, when I do the auto format in Android Studio for these dart code, it give me the result in the picture below.

It give me not only an ugly code formatting, but also a wrong feeling of the scope of function.

Is there any way can help me to solve this issue?

enter image description here

Costanza answered 3/3, 2019 at 14:10 Comment(1)
Add a comma after }Snotty
B
11

I think yours is an issue of trailing comma.

dartfmt actually uses trailing commas to determine when to go to the next line, and yours is missing one at the end of your code. Try reading this to understand why this is an issue.

Bejarano answered 3/3, 2019 at 17:3 Comment(1)
You saved me a lot of pain. Thanks!Tramway

© 2022 - 2024 — McMap. All rights reserved.