Converted GuessInput to a StatefulWidget in Stateful widgets tutorial - #13653
Conversation
|
Staged preview of the updated docs.flutter.dev site (updated for commit e5ba16f): https://flutter-docs-prod--docs-pr13653-mg-guessinput-issue-3th19sc7.web.app |
|
Staged preview of the updated flutter.dev site (updated for commit e5ba16f): https://flutter-dev-230821--www-pr13653-mg-guessinput-issue-hk3zmet1.web.app |
MuthuGCodes
left a comment
There was a problem hiding this comment.
Incorporated review comments
There was a problem hiding this comment.
Code Review
This pull request converts the GuessInput widget from a StatelessWidget to a StatefulWidget in the Birdle example to properly manage the lifecycles of TextEditingController and FocusNode, including their disposal. It also updates the tutorial documentation to explain this transition. Feedback was provided to correct a conceptual explanation in the documentation regarding Flutter's widget recreation lifecycle, clarifying that controllers persist because they are moved to the persistent State object rather than being recreated with the widget instance.
parlough
left a comment
There was a problem hiding this comment.
Thanks for tackling this @MuthuGCodes, this is a great way to tackle the problem and further instruction around stateful vs stateless widgets.
Generally looks good to me. There's just one inconsistency between previous steps and this one:
|
LGTM. Please incorporate @parlough's feedback. |
|
Thanks for those updates @MuthuGCodes! |
Rebuilding
GamePage(after converting it toStatefulWidget) recreatesGuessInput(which is currently aStatelessWidget), resetting its internalFocusNodeandTextEditingControllerand breaking focus behavior. The fix is to convertGuessInputto aStatefulWidgetin the "Stateful widgets" tutorial step and the example code.Fixes #13392