-
Notifications
You must be signed in to change notification settings - Fork 326
Option to "Convert to Stateless Widget" #3734
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
Comments
@scheglov Does this seem like a reasonable request? I'd be concerned that our list of actions might get too large if we do everything. |
I figured it would be natural to add the companion. Also, it wouldn't be
present at the same time as the convert to stateful, so the list length
would stay the same
…On Tue, Aug 6, 2019, 7:49 AM stevemessick ***@***.***> wrote:
@scheglov <https://github.com/scheglov> Does this seem like a reasonable
request? I'd be concerned that our list of actions might get too large if
we do everything.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3734?email_source=notifications&email_token=AFPYO7OK2PAP2YBPDGU6AMTQDGFQLA5CNFSM4IJNHC6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3VMRAQ#issuecomment-518703234>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFPYO7I2LKBUKAWLVXFS4BTQDGFQLANCNFSM4IJNHC6A>
.
|
@ThinkDigitalSoftware could you please provide a couple of example when it should happen, and when not? |
Sure. In this case, it should show up, since this is an easy conversion with no possible side effects. I.E. move the build function and delete the createState. class SampleWidget extends StatefulWidget {
@override
_SampleWidgetState createState() => _SampleWidgetState();
}
class _SampleWidgetState extends State<SampleWidget> {
@override
Widget build(BuildContext context) {
return Container();
}
} In this case, all variables are immutable. No setState calls. class SampleWidget extends StatefulWidget {
@override
_SampleWidgetState createState() => _SampleWidgetState();
}
class _SampleWidgetState extends State<SampleWidget> {
final variableA = 7;
@override
Widget build(BuildContext context) {
return Container();
}
} no variables are reassigned here, no setState calls. variable can be made immutable and moved over. class SampleWidget2 extends StatefulWidget {
@override
_SampleWidget2State createState() => _SampleWidget2State();
}
class _SampleWidget2State extends State<SampleWidget2> {
String aString = "Hello, world";
@override
Widget build(BuildContext context) {
return Container();
}
} The cases where it shouldn't show up are all the cases not shown here. If a widget has state that's internally managed, it's not available for that refactor. If setState is used... My use case is that I switched to managing the state of my widget to outside of the widget. I moved out all the mutable variables and then had to cut, paste and delete (and change Stateful to Stateless) to get it done. |
I've found myself wanting this refactor a few times. Often you have a stateful widget and then you perform some refactors so it can be stateless but it takes a lot of manual boilerplate renames to make it a stateless widget (e.g. remove |
This issue was moved by helin24 to dart-lang/sdk#46011. |
Can we have the option to convert to a stateless widget if all variables if any are immutable?
The text was updated successfully, but these errors were encountered: