Fix GuessInput focus persistence using StatefulWidget#13402
Fix GuessInput focus persistence using StatefulWidget#13402harshyadavDeveloper wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the GuessInput widget from a StatelessWidget to a StatefulWidget to properly manage the lifecycle of the TextEditingController and FocusNode, including their disposal. A review comment suggests adding a length validation check in the _onSubmit method to ensure that only five-letter guesses are processed, which prevents potential runtime errors when interacting with the underlying game logic.
|
Thanks for catching this. I added a length check before submitting guesses so invalid input no longer reaches |
|
Visit the preview URL for this PR (updated for commit 54a3f36): https://flutter-docs-prod--pr13402-fix-guessinput-focus-lifecy-9htefr8i.web.app |
|
/gcbrun |
|
Staged preview of the updated docs.flutter.dev site (updated for commit 771bb0f): https://flutter-docs-prod--docs-pr13402-fix-guessinput-focus-l-bb1n29hd.web.app |
|
/gcbrun |
|
@parlough, the build is failing and all it says is that a file needs formatting, but doesn't state which file. Can you assist? |
parlough
left a comment
There was a problem hiding this comment.
Thanks for this PR! However, it will require larger changes as GuessInput is implemented and referenced throughout the User input lesson (source) with excerpt sources implementing various stages across multiple Dart files in https://github.com/flutter/website/tree/main/examples/fwe/birdle/lib.
So a full solution will need to adjust the text and code snippets of at least that lesson to account for and explain these changes. If you'd be interested in doing that in, it might be best to start with a proposal in the issue. I'd be happy to answer any questions you have designing or implementing those changes. Otherwise, feel free to close this PR and we'll tackle the changes when we can.
Thanks again and sorry if this wasn't clear before!
Description of what this PR is changing or adding, and why:
Converts
GuessInputfrom aStatelessWidgetto aStatefulWidgetto preserve theFocusNodeandTextEditingControlleracross rebuilds.This ensures
_focusNode.requestFocus()works as intended aftersubmitting input and demonstrates proper lifecycle management for
long-lived objects used by text fields.
The change also adds disposal for the
FocusNodeandTextEditingControllerto avoid resource leaks.Issues fixed by this PR (if any):
Fixes #13392
PRs or commits this PR depends on (if any):
None.
Presubmit checklist
of 80 characters or fewer.