4

My dart file is formatted weirdly

    return Scaffold(
        backgroundColor: bgColor,
        body: SafeArea(
            child: Container(
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage('assets/$bgImage'), fit: BoxFit.cover)),
          child: Padding(
            padding: const EdgeInsets.fromLTRB(0, 120, 0, 0),
            child: Column(
              children: <Widget>[
                FlatButton.icon(

How to do the settings so the normal widget tree can indent properly.

Also, I've set "editor.rulers": [120], this still give me auto indentation that I do not want:

                    onPressed: () async {
                      **dynamic result =
                          await Navigator.pushNamed(context, '/location');**
                      setState(() {
                        data = {
                          'time': result['time'],
                          'location': result['location'],
                          'flag': result['flag'],
                          'isDaytime': result['isDaytime']
                        };
                      });
                    },
2
  • vs code tells you to put a trailing comma right
    – Yadu
    Commented Jul 31, 2020 at 4:39
  • not really, vscode does't have warning or error there
    – Hang Alec
    Commented Jul 31, 2020 at 8:02

1 Answer 1

26

Use trailing commas in the arguments list.

Without trailing commas:

Foo(arg1: ..., arg2: ...)

With trailing commas:

Foo(
  arg1: ...,
  arg2: ..., // notice the comma
)

for eg.:

decoration: BoxDecoration(
  image: DecorationImage(
    image: AssetImage('assets/$bgImage'), 
    fit: BoxFit.cover, // add a comma here
  ), // add a comma here
),
2
  • the ling where decoration: BoxDecoration( is not indented though.
    – Hang Alec
    Commented Jul 31, 2020 at 8:09
  • 1
    Make sure the arguments list of the container ends with a trailing comma. Commented Jul 31, 2020 at 8:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.