Skip to content

When click on "Create constructor with final fields, required named", it generates syntax error #56182

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

Closed
bwilkerson opened this issue Jul 8, 2024 · 4 comments
Assignees
Labels
devexp-assist Issues with analysis server assists legacy-area-analyzer Use area-devexp instead. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@bwilkerson
Copy link
Member

STEPS TO REPRODUCE:

  • Create a Flutter project with Dart language
  • Create a Dart class
  • Create a attribute starting with underscore
  • Mouse over on the name of attribute
  • Click on More Options...
  • Select the "Create constructor with final fields, required named" option
  • The IDE will generate the constructor with syntax error: "Named parameters can't start with an underscore"

Possible solution

When click on "Create constructor with final fields, required named", it would be interesting generate like the following:

const ButtonIncrementDefault({super.key, required Widget buttonChild, required void Function() onPressed})
      : _buttonChild = buttonChild, _onPressed = onPressed;

Instead of:

 const ButtonIncrementDefault({super.key, required this._buttonChild, required this._onPressed});
@bwilkerson bwilkerson added legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) devexp-assist Issues with analysis server assists labels Jul 8, 2024
@bwilkerson
Copy link
Member Author

@eljames

Is ButtonIncrementDefault a subclass (directly or indirectly) of Flutter's Widget class? I suspect so, but wanted to confirm in order to make it easier to debug the problem.

@eljames
Copy link

eljames commented Jul 8, 2024

@eljames

Is ButtonIncrementDefault a subclass (directly or indirectly) of Flutter's Widget class? I suspect so, but wanted to confirm in order to make it easier to debug the problem.

@bwilkerson Yes. The ButtonIncrementDefault is subclass of Widget.
But I didn't imagine that the problem can show only on Widget subclasses. I will test for other than Widget subclasses. Thank you.

@bwilkerson
Copy link
Member Author

I don't know whether the problem is isolated to widgets, I just know that a quick glance at the implementation showed that we are special casing widgets in at least one place. The problem might be completely unrelated, I haven't yet tried writing a test.

@keertip keertip added the P3 A lower priority bug or feature request label Jul 10, 2024
@scheglov
Copy link
Contributor

@fshcheglov I think this is a good issue for you to solve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-assist Issues with analysis server assists legacy-area-analyzer Use area-devexp instead. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants