android-studiodartflutterauto-indent

Change the Auto-Indent Lines setting when using Flutter in Android Studio


Problem

Auto-Indent Lines improperly shifts indent of Redirecting constructors.

The result of Auto-Indent is below.

 Project.getInbox()
    : this.update(
    foo: 1,
    bar: 2,
    baz: 3);

The result I want is below.

 Project.getInbox()
     : this.update(
           foo: 1,
           bar: 2,
           baz: 3);

Question

Development Environment

Tried → Error

Best regards,


Solution

  • Dart (and therefore Flutter) uses its own code formatter dartfmt, so it's not possible to control indentation etc through the IDE. In this case, dartfmt will format the code differently depending on the optional trailing comma.

    Without

      Project.getInbox() : this.update(foo: 1, bar: 2, baz: 3);
    

    With

      Project.getInbox()
          : this.update(
              foo: 1,
              bar: 2,
              baz: 3,
            );