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

Convert to StatefulWidget adds an extra underscore to private widgets #3343

Closed
jorgecoca opened this issue May 14, 2021 · 12 comments
Closed
Labels
in flutter Relates to running Flutter apps in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement
Milestone

Comments

@jorgecoca
Copy link

Describe the bug
If you have a private StatelessWidget that you'd like to turn into a StatefulWidget, when you using the VS Code helper to do so your new State class will be prefixed with an extra underscore:

For example, if your class name was _MyCustomWidget, when using Convert to StatefulWidget the new state generated will be__MyCustomWidgetState (notice the two underscores at the beginning)

To Reproduce

  1. Create a private StatelessWidget
  2. Click on Convert to StatefulWidget and see the new state being prefixed by 2 underscores.
    Screen Shot 2021-05-14 at 9 13 37 AM

Expected behavior
The new state generated only has one underscore.

Versions (please complete the following information):

  • VS Code version: 1.56.2
  • Dart extension version: 3.22.0
  • Dart/Flutter SDK version: Flutter (Channel beta, 2.2.0-10.3.pre, on macOS 11.2.3 20D91 darwin-x64, locale en-US)
@jorgecoca
Copy link
Author

I will fork the project and try to provide a fix for this.

@DanTup
Copy link
Member

DanTup commented May 17, 2021

Thanks for the report! This fix actually comes from the Dart analysis server, so the fix will need to be made there.

If you'd like to contribute this, I believe the relevant code is here:

https://github.com/dart-lang/sdk/blob/bee609fd6b09d3e122ab279d58d9154a7f5f1263/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateful_widget.dart#L60

And tests for this functionality are at:

https://github.com/dart-lang/sdk/blob/bee609fd6b09d3e122ab279d58d9154a7f5f1263/pkg/analysis_server/test/src/services/correction/assist/flutter_convert_to_stateful_widget_test.dart

You'd need to clone and set up the Dart SDK, instructions for which are here:

Otherwise, if that's more involved than you'd expected and you'd prefer someone else to fix it, I'm happy to have a look - just let me know. Thanks!

@DanTup DanTup added this to the v3.23.0 milestone May 17, 2021
@DanTup DanTup added in flutter Relates to running Flutter apps in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement and removed is bug labels May 17, 2021
@jorgecoca
Copy link
Author

Oh thank you for pointing me in the right direction! This is super helpful! I will make the changes there ;)

@MrBirb
Copy link

MrBirb commented May 19, 2021

I have a PR submitted https://dart-review.googlesource.com/c/sdk/+/200720

@DanTup
Copy link
Member

DanTup commented May 20, 2021

@MrBirb great! You'll need to run "Dart: Sort Members" in the analysis_server/test/src/services/correction/assist/flutter_convert_to_stateful_widget_test.dart file to fix the test failure.

@MrBirb
Copy link

MrBirb commented May 20, 2021

@DanTup Done :D

@DanTup
Copy link
Member

DanTup commented May 20, 2021

Awesome - thanks! I'll close this once that change is merged :-)

@jorgecoca
Copy link
Author

Wohooo! Thank you @MrBirb !!!

dart-bot pushed a commit to dart-lang/sdk that referenced this issue May 20, 2021
Bug: Dart-Code/Dart-Code#3343

Change-Id: Ica188ab06e24b4d0708bdc1e23aefeebb53bcab2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200720
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
@DanTup
Copy link
Member

DanTup commented May 25, 2021

Fixed by dart-lang/sdk@5051d4b which will be included in a future SDK update.

@DanTup DanTup closed this as completed May 25, 2021
@Mayb3Nots
Copy link

Mayb3Nots commented Jun 18, 2021

Hi @DanTup , I am not seeing this is the lastest SDK. Am I missing something?

Flutter 2.2.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision d79295af24 (7 days ago) • 2021-06-11 08:56:01 -0700
Engine • revision 91c9fc8fe0
Tools • Dart 2.13.3

@DanTup
Copy link
Member

DanTup commented Jun 18, 2021

@Mayb3Nots the hotfix releases only include very specific fixes for critical issues, so this will only show up with the next normal release (eg. 2.3 or later, not 2.2.x releases). Sorry for the confusion!

@Mayb3Nots
Copy link

@Mayb3Nots the hotfix releases only include very specific fixes for critical issues, so this will only show up with the next normal release (eg. 2.3 or later, not 2.2.x releases). Sorry for the confusion!

Thanks for the clarification, was wondering why some of the fixes wasnt working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in flutter Relates to running Flutter apps in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement
Projects
None yet
Development

No branches or pull requests

4 participants