[State Restoration] Restorable FormField and TextFormField#78835
[State Restoration] Restorable FormField and TextFormField#78835shihaohong merged 17 commits intoflutter:masterfrom shihaohong:sr-text-form-field
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.
Why this change? (It will not longer be linked in docs...)
There was a problem hiding this comment.
Same question for other locations in this PR as well.
There was a problem hiding this comment.
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.
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! |
|
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.