Skip to content

Conversation

@shihaohong
Copy link
Contributor

@shihaohong shihaohong commented Mar 23, 2021

Makes FormField, and TextFormField state restorable. An interesting situation with this is that FormField contains an internal generically typed _value. I'm not sure how to handle in a straightforward way since there's no guarantee that T is serializable. So to deal with this in TextFormField, I explicitly call setValue in restoreState to make sure that the internal value in FormFieldState is kept in sync with the _controller value whenever restoreState is called.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

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.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Mar 23, 2021
@google-cla google-cla bot added the cla: yes label Mar 23, 2021
@shihaohong shihaohong changed the title WIP - [State Restoration] Restorable TextFormField and FormFieldState [State Restoration] Restorable TextFormField and FormFieldState Mar 24, 2021
@shihaohong shihaohong requested a review from goderbauer March 24, 2021 07:13
@shihaohong shihaohong changed the title [State Restoration] Restorable TextFormField and FormFieldState [State Restoration] Restorable Form, FormField and TextFormField Mar 24, 2021
@shihaohong shihaohong requested review from justinmc and removed request for justinmc March 24, 2021 08:56
@shihaohong shihaohong changed the title [State Restoration] Restorable Form, FormField and TextFormField [State Restoration] Restorable FormField and TextFormField Mar 24, 2021
/// * [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].
Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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

@shihaohong shihaohong requested a review from goderbauer April 14, 2021 08:38
@shihaohong
Copy link
Contributor Author

Should be ready for another round of review!

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shihaohong
Copy link
Contributor Author

The Google testing failures appear to be flakes. I reran them (internal link) and they're passing.

@shihaohong shihaohong merged commit 3eeadc2 into flutter:master Apr 14, 2021
@shihaohong shihaohong deleted the sr-text-form-field branch April 14, 2021 23:50
auto-submit bot pushed a commit that referenced this pull request Mar 5, 2024
## Description

This PR makes `CupertinoTextFormFieldRow` restorable.
The implementation is based on #78835 which made `FormField` and `TextFormField` restorable.

## Related Issue

Fixes #144504.

## Tests

Adds 4 tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: state restoration RestorationManager and related APIs f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants