Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio wrong auto indent for dart

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

like image 430
kin lau Avatar asked Dec 23 '22 00:12

kin lau


1 Answers

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.

like image 77
Esh Avatar answered Dec 25 '22 13:12

Esh