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
[SuperTextField] Fix setState called during build phase (Resolves #1980) #1981
Conversation
@knopp Could you please try this PR? Or could you provide more info on how to reproduce this issue? |
_log.info('Attaching TextInputClient to TextInput'); | ||
// The focus change callback might be invoked in the build phase. It that's the case, | ||
// defer the setState call until the end of the frame. | ||
WidgetsBinding.instance.runAsSoonAsPossible(() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we have a method that automatically bails when not mounted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have for run code always on the next frame, but not to run it as soon as possible
@angelosilvestre - Let's also document in code the call path that results in calling the method during build. It sounds like it originates in OverlayPortal. |
@angelosilvestre, this fixed the failing tests that we had. Thanks! |
@matthew-carroll Updated. |
@matthew-carroll, can this be merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[SuperTextField] Fix setState called during build phase. Resolves #1980
The focus change callback seems to be invoked during the build phase sometimes. In our focus change callback we call
setState
, which causes a Flutter violation (callingmarkNeedsBuild
during build phase).I wasn't able to reproduce this issue locally, but the fix should be obvious: when the callback is invoked during build, we need to defer the call to
setState
until the end of the frame.