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? |
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.