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

Arrow function is formatted with first line on next line if whole body does not fit on one line #1649

Open
navaronbracke opened this issue Feb 15, 2025 · 0 comments

Comments

@navaronbracke
Copy link

navaronbracke commented Feb 15, 2025

While the new formatting style is a step in the right direction, I have seen it do something odd for arrow functions.

Considering the following settings:

environment:
  sdk: ">=3.7.0 <4.0.0"

formatter:
  page_width: 120

The following code is formatted with the first line of the arrow function on the next line, instead of the line it was at with the old style, even though that first line would definitely fit on one line.
This is a bit of a disruptive change, as it introduces an odd indentation for code that is otherwise fine to read.
I am aware that this is opinionated, but I think that fixing this is probably good for readability.
I have also seen frustration from other devs about this change, so maybe we can correct it?

The "workaround" is just to use a block body in this case, but some people probably prefer arrow functions over block bodies.

Actual

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: controller,
      builder: (context, child) {
        if (validator(context, controller.value.text) != null) {
          return const SizedBox.shrink();
        }

        return PlatformAwareWidget(
          android:
              (context) => IconButton(
                color: Theme.of(context).colorScheme.primary,
                icon: const Icon(Icons.check),
                onPressed: onTap,
              ),
          ios: (context) => CupertinoIconButton(icon: CupertinoIcons.checkmark_alt, onPressed: onTap),
        );
      },
    );
  }

Expected

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: controller,
      builder: (context, child) {
        if (validator(context, controller.value.text) != null) {
          return const SizedBox.shrink();
        }

        return PlatformAwareWidget(
          android: (context) => IconButton(
            color: Theme.of(context).colorScheme.primary,
            icon: const Icon(Icons.check),
            onPressed: onTap,
          ),
          ios: (context) => CupertinoIconButton(icon: CupertinoIcons.checkmark_alt, onPressed: onTap),
        );
      },
    );
  }
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

1 participant