-
Notifications
You must be signed in to change notification settings - Fork 29.8k
[State Restoration] Restorable FormField and TextFormField #78835
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
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
| /// * [GlobalKey], a key that is unique across the entire app. | ||
| /// * [FormField], a single form field widget that maintains the current state. | ||
| /// * [TextFormField], a convenience widget that wraps a [TextField] widget in a [FormField]. | ||
| /// * `TextFormField`, a convenience widget that wraps a [TextField] widget in a [FormField]. |
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.
Why this change? (It will not longer be linked in docs...)
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.
Same question for other locations in this PR as well.
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.
Oops, I think this change was introduced by accident. I'll revert it
|
|
||
| class _TextFormFieldState extends FormFieldState<String> { | ||
| TextEditingController? _controller; | ||
| late final RestorableTextEditingController _controller = RestorableTextEditingController(text: widget.initialValue); |
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 should only have this instantiated if we actually need it, similarly to how we do it in the Textfield itself: https://github.com/flutter/flutter/pull/63401/files
|
Should be ready for another round of review! |
goderbauer
left a comment
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
|
The |
Makes
FormField, andTextFormFieldstate restorable. An interesting situation with this is thatFormFieldcontains an internal generically typed_value. I'm not sure how to handle in a straightforward way since there's no guarantee thatTis serializable. So to deal with this inTextFormField, I explicitly callsetValueinrestoreStateto make sure that the internal value inFormFieldStateis kept in sync with the_controllervalue wheneverrestoreStateis called.Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.