Skip to content

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

Closed

Description

@jorgecoca

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)

Activity

  1. jorgecoca commented on May 14, 2021

    @jorgecoca
    Author

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

  2. DanTup commented on May 17, 2021

    @DanTup
    Member

    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!

  3. added this to the v3.23.0 milestone on May 17, 2021
  4. added
    in flutterRelates to running Flutter apps
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    and removed on May 17, 2021
  5. jorgecoca commented on May 17, 2021

    @jorgecoca
    Author

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

  6. thecalamiity commented on May 19, 2021

    @thecalamiity
  7. DanTup commented on May 20, 2021

    @DanTup
    Member

    @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.

  8. thecalamiity commented on May 20, 2021

    @thecalamiity

    @DanTup Done :D

  9. DanTup commented on May 20, 2021

    @DanTup
    Member

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

  10. jorgecoca commented on May 20, 2021

    @jorgecoca
    Author

    Wohooo! Thank you @mrbirb !!!

  11. DanTup commented on May 25, 2021

    @DanTup
    Member

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

  12. Mayb3Nots commented on Jun 18, 2021

    @Mayb3Nots

    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
    
  13. DanTup commented on Jun 18, 2021

    @DanTup
    Member

    @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!

  14. Mayb3Nots commented on Jun 18, 2021

    @Mayb3Nots

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    in flutterRelates to running Flutter appsin lsp/analysis serverSomething to be fixed in the Dart analysis serveris enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions