question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong indent while formatting nested children in an array

See original GitHub issue

While using a Ctrl+Shift+I formatter tool I always got great results until I stumbled onto this odd indent behavior:

dartcode-format1

Notice how indent of Column widget fields is off by 2 indent levels. What I believe it should look like (manually formatted):

dartcode-format2

If I remove Expanded widget which wraps the Column widget, indent starts to behave normally.

Version info:

VS Code

Version: 1.30.0
Commit: c6e592b2b5770e40a98cb9c2715a8ef89aec3d74
Date: 2018-12-11T22:21:33.585Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
OS: Linux x64 4.19.8-arch1-1-ARCH

Dart Code

Name: Dart
Id: dart-code.dart-code
Description: Dart language support and debugger for Visual Studio Code.
Version: 2.21.1
Publisher: Dart Code
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=dart-code.dart-code

P.S. I might have given a too generic name to this issue, maybe it should be renamed after you understand the issue.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
DanTupcommented, Dec 20, 2018

Thanks for the report. I think this is actually expected - I can repro with this code:

  @override
  Widget build(BuildContext context) {
    return Expanded(
        child: Column(
      children: const <Widget>[],
    ));
  }

The issue is the two closing parens at the end )). There’s no trailing comma between them, which means Expanded is not being formatted “the flutter way”. If you insert it it ends up formatted like this:

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Column(
        children: const <Widget>[],
      ),
    );
  }

Similarly, if you insert a , between the last two parens in your method, it gets reformatted like this:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('test'),
      ),
      body: Row(children: <Widget>[
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: const <Widget>[
              Text('test'),
              Text('test'),
            ],
          ),
        )
      ]),
    );
  }

Hope this helps!

5reactions
dimsuzcommented, Dec 20, 2018

Oh, I didn’t know this comma-related convention exists for Flutter formatting. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

clang-format weird indentation of array of structs in C++
At first you need to add an ContinuationIndentWidth: 2 option to your format file. Then add a comma after the last item in...
Read more >
Markdown: nested ordered lists are formatted incorrectly ...
Markdown: nested ordered lists are formatted incorrectly when not using default indentation · 1. Change tab size and indent to 2 spaces. ·...
Read more >
indent - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
CoffeeScript
Destructuring assignment can be used with any depth of array and object nesting, to help pull out deeply nested properties.
Read more >
Shell Style Guide - Google
Formatting, Indentation - Line Length and Long Strings - Pipelines - Loops - Case ... Expansion of Filenames - Eval - Arrays -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found