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

=> closures formatting in named argument list #1545

Open
goderbauer opened this issue Aug 20, 2024 · 1 comment
Open

=> closures formatting in named argument list #1545

goderbauer opened this issue Aug 20, 2024 · 1 comment

Comments

@goderbauer
Copy link

The new dart formatter wants to format this as follows:

void _showDialog(Widget child, BuildContext context) {
  showCupertinoModalPopup<void>(
    context: context,
    builder:
        (BuildContext context) => Container(
          height: 216,
          padding: const EdgeInsets.only(top: 6.0),
          // The Bottom margin is provided to align the popup above the system
          // navigation bar.
          margin: EdgeInsets.only(
            bottom: MediaQuery.of(context).viewInsets.bottom,
          ),
          // Provide a background color for the popup.
          color: CupertinoColors.systemBackground.resolveFrom(context),
          // Use a SafeArea widget to avoid system overlaps.
          child: SafeArea(top: false, child: child),
        ),
  );
}

This gives the closure a lot of prominence over the other parameters and also causes more indentation reducing the effective line length for code inside the closure.

void _showDialog(Widget child, BuildContext context) {
  showCupertinoModalPopup<void>(
    context: context,
    builder: (BuildContext context) => Container(
      height: 216,
      padding: const EdgeInsets.only(top: 6.0),
      // The Bottom margin is provided to align the popup above the system
      // navigation bar.
      margin: EdgeInsets.only(
        bottom: MediaQuery.of(context).viewInsets.bottom,
      ),
      // Provide a background color for the popup.
      color: CupertinoColors.systemBackground.resolveFrom(context),
      // Use a SafeArea widget to avoid system overlaps.
      child: SafeArea(top: false, child: child),
    ),
  );
}

This formatting would visually also be more in line with the formatting I'd expect if builder were a list argument:

void _showDialog(Widget child, BuildContext context) {
  showCupertinoModalPopup<void>(
    context: context, 
    builder: <Widget>[
      longNameForAWidgetToMakeSureThisDoesNotFit,
      longNameForAWidgetToMakeSureThisDoesNotFit2,
      longNameForAWidgetToMakeSureThisDoesNotFit3,
    ],
  );
}

@munificent did mention that there are cases were this kind of formatting for => closures looks worse. I'm interested in seeing examples for that.

@FMorschel
Copy link

The same happens in #1525 although it is not a named argument case but a cascade case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants