skip to Main Content

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

Answers


  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.

    Login or Signup to reply.
  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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search