2

I am developing with Flutter using Android Studio. When I try to format the code using the Cmd + Opt + L keys, it ends up like #1 below. Is there a good way to make it look like #2?

//#1
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
            child: Column(
      children: [
        const Text("signup page"),
        ElevatedButton(
            onPressed: () {
              debugPrint("");
            },
            child: const Text(""))
      ],
    )));
  }
//#2

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: [
            const Text("signup page"),
            ElevatedButton(
              onPressed: () {
                debugPrint("");
              },
              child: const Text("")
            )
          ],
        )
      )
    );
  }

I tried using analysis_options.yaml and .editorconfig, but I couldn't find an option to configure it the way I want. Is there anything I might have missed?

2
  • 1
    control+shift+f Commented Oct 3, 2024 at 6:52
  • Try cmd+alt+L key to format code. Commented Oct 3, 2024 at 6:59

2 Answers 2

2

To formate the code you have to add commas , commas make the code take the line for itself,

like this:

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: [
            const Text("signup page"),
            ElevatedButton(
              onPressed: () {
                debugPrint("");
              },
              child: const Text(""),
            ),
          ],
        ),
      ),
    );
  }

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

1

this is the first kind with dart autoformatting

Text ('abcd',style:textstyle:fontSize: 20),  

but the same code can be arranged as

Text ('abcd',
      style:textstyle:fontSize: 20,
),  

how can this be done? simply add a comma at the end of line.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.