-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Add a "design discussion" section to the setState method #12296
Comments
We used to just have a We changed to a method that takes a (synchronously-invoked) callback, and suddenly people had much less trouble with it. We found people understand much more easily that if you didn't change any state, you don't need to call it; if you did change some state, you call it and change the state during the call. Eventually we plan to make some lints verify that anything you use in your |
I'll add a "Design discussion" section to the setState docs talking about this. Let me know if there's anything else you'd like covered in the docs for this, I'm happy to add more information there. |
Maybe the better docs was needed for Otherwise, thanks for the explanation! :) |
Maybe, but in my experience we shouldn't depend on people reading API docs. :-)
That would be inconsistent with our naming guide: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#naming-rules-for-typedefs-and-function-variables
It's a pretty small cost when called once per frame (which is what you generally expect for setState). Also, it's not called during performance-critical periods; it's called in response to user input generally and so we have more CPU to play with here than if it was during the frame itself. Also eventually I wouldn't be surprised if we were able to get the compiler to just inline this.
Needless is subjective here. I would argue the need is to show that this is the block that is actually mutating the state.
Well as noted above, in practice it seems to have actually reduced it.
Yup, that's why we need to add more to the documentation. :-) |
Closing, as there are several places in our documentation nowadays that talk about |
@Hixie Is there any issue tracking this? |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
https://medium.com/@mehmetf_71205/setting-the-state-2809936fb79d also has some context |
This issue is assigned to @Hixie but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks! |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
I just started playing with Flutter, and the most obvious stuff is
setState
. Honestly, it does not look good. Why would you want to put all your mutations into a lambda, especially if they are all side-effecting? Wouldn't it be better just to callupdate()
directly after you do all the state mutations?The pattern looks like it came from a functional architecture, but the main point is missing - state mutation should have been encapsulated inside
setState
function, but this is not the case for Flutter. Without immutability, pure lambda and state change encapsulation all of this doesn't seems have any meaning.The text was updated successfully, but these errors were encountered: