Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget instantiation indents first named argument by 4 spaces in stead of two #1962

Closed
agmcleod opened this issue Sep 2, 2019 · 3 comments
Closed
Labels
working as intended Described behaviour is expected.

Comments

@agmcleod
Copy link

agmcleod commented Sep 2, 2019

Hi there, I did see the issue where this cannot work with tabs but I am using 2 spaces, so I think I should be fine. #1015

Anyways, the issue im seeing is that when you're initializing a widget, the first argument indents by 4 spaces, and makes it look a little off. Here's a single file I've been working on that shows it:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _MyAppState();
  }
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(title: Text('EasyList')),
      body: Column(children: <Widget>[
        Container(
          margin: EdgeInsets.all(10.0),
          child: RaisedButton(
            onPressed: () {},
            child: Text('Add Product'),
          ),
        ),
        Card(
            child: Column(
          children: <Widget>[
            Image.asset('assets/food.jpg'),
            Text('Food Paradise'),
          ],
        )),
      ]),
    ));
  }
}

Can see that home: Scaffold( is indented one too far, and that kind makes the nested arguments below it look weird too.

I've also captured the logs here in case it's helpful.

Dart-Code-Log-2019-08-01 14-49-12.txt

@DanTup
Copy link
Member

DanTup commented Sep 3, 2019

I believe this is caused by a missing trailing comma near the end of your code:

    ));
  }
}

Without trailing commas dartfmt indents wrapped lines using 4 spaces. Here your code has a mix, so you end up with some lines formatted one way and some the other.

Let me know if this doesn't help!

@agmcleod
Copy link
Author

agmcleod commented Sep 3, 2019

It does thank you! Is there a way to have it auto add trailing commas?

@DanTup
Copy link
Member

DanTup commented Sep 3, 2019

Great! :-)

I don't know of one - there's some discussion over at dart-lang/sdk#27084 about this, but I think it's hard to know when commas should/shouldn't be added. I'd recommend subscribing to and/or commenting on that issue, since any fix for this would need to come from the SDK or dartfmt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
working as intended Described behaviour is expected.
Projects
None yet
Development

No branches or pull requests

2 participants