Ali Faris
Ali Faris

Reputation: 18592

android studio not formatting dart code correctlly

I'm writing flutter app, and I have this block of dart code

  Widget launchScreen() {
    return Screen(
        child: Container(
            color: Colors.lightBlue,
            child: Center(
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Container(
                          height: 200, 
                          width: 200, 
                          child: Image.asset("resources/images/logo.png")
                      ),
                    ]
                )
            )
        )
    );
  }

which seems very neat and well indented, but after running Reformat Code in Android Studio, the result is so ugly and stupid

  Widget launchScreen() {
    return Screen(
        child: Container(
            color: Colors.lightBlue,
            child: Center(
                child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
              Container(height: 200, width: 200, child: Image.asset("resources/images/logo.png")),
            ]))));
  }

I tried to update the code style for dart in the settings but I can't find any options to be customized only the line width.

is there a way to improve(fix) the formatting?

Upvotes: 0

Views: 685

Answers (2)

Ravindra S. Patil
Ravindra S. Patil

Reputation: 14775

Try to add , after ] and )
      
   Widget launchScreen() {
    return Screen(
      child: Container(
        color: Colors.lightBlue,
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Container(
                height: 200,
                width: 200,
                child: Image.asset(
                  "resources/images/logo.png",
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

Upvotes: 2

Lucas Josino
Lucas Josino

Reputation: 835

Dart format use the , has parameter

Screen(
  child: Container(
    color: Colors.lightBlue,
    child: Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
            height: 200,
            width: 200,
            child: Image.asset("resources/images/logo.png"),
          ),
        ],
      ),
    ),
  ),
);

Upvotes: 3

Related Questions