You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Convert to StatefulWidget adds an extra underscore to private widgets #3343
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
Create a private StatelessWidget
Click on Convert to StatefulWidget and see the new state being prefixed by 2 underscores.
Expected behavior
The new state generated only has one underscore.
Versions (please complete the following information):
@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.
@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 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.
Activity
jorgecoca commentedon May 14, 2021
I will fork the project and try to provide a fix for this.
DanTup commentedon 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!
jorgecoca commentedon May 17, 2021
Oh thank you for pointing me in the right direction! This is super helpful! I will make the changes there ;)
thecalamiity commentedon May 19, 2021
I have a PR submitted https://dart-review.googlesource.com/c/sdk/+/200720
DanTup commentedon 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.dartfile to fix the test failure.thecalamiity commentedon May 20, 2021
@DanTup Done :D
DanTup commentedon May 20, 2021
Awesome - thanks! I'll close this once that change is merged :-)
jorgecoca commentedon May 20, 2021
Wohooo! Thank you @mrbirb !!!
Convert private widget to Stateful without extra underscore.
DanTup commentedon May 25, 2021
Fixed by dart-lang/sdk@5051d4b which will be included in a future SDK update.
Mayb3Nots commentedon Jun 18, 2021
Hi @DanTup , I am not seeing this is the lastest SDK. Am I missing something?
DanTup commentedon 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 commentedon Jun 18, 2021
Thanks for the clarification, was wondering why some of the fixes wasnt working.