question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Convert to StatefulWidget adds an extra underscore to private widgets

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jorgecocacommented, May 20, 2021

Wohooo! Thank you @MrBirb !!!

1reaction
MrBirbcommented, May 19, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Converting a Stateful Widget App to Using Provider for State ...
Move your image_picker import to your state file; Remove the underscore in the function names so they're no longer private; Delete the setState ......
Read more >
Google Flutter - Stateful Widgets - Jilli Boutique
Code in this class can refer to Stateful Widget by using the 'widget' variable. Sometimes this class uses an underscore prefix in its...
Read more >
Keeping final fields on the Widget or the State? - Stack Overflow
The StatefulWidget 's associated State should use only the default constructor (no arguments), and its member fields should be private ...
Read more >
Flutter: State Management with Stateful Widgets
A stateful widget can change its appearance in response to user ... This returned widget gets added as a child to the parent...
Read more >
Adding interactivity to your Flutter app
A stateful widget is dynamic: for example, it can change its appearance in ... Note: Members or classes that start with an underscore...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found