Repository navigation
Refresh FormField errors after locale changes - #191110
abdullahtas0 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates FormFieldState to re-validate and update its error text when the active locale changes. This is done by tracking the locale in didChangeDependencies and triggering validation if the locale changes while the field is enabled and has an error. Feedback suggests removing the _locale != null check to ensure that restored form states with existing errors are correctly re-validated and translated on the initial build.
| if (_locale != null && locale != _locale && widget.enabled && hasError) { | ||
| _validate(); | ||
| } |
There was a problem hiding this comment.
By requiring _locale != null, the field will not re-validate on the very first didChangeDependencies call. However, if the form state was restored and already has an error (hasError is true), we want to re-validate on the first build to ensure the restored error message is correctly translated to the current user locale. Removing _locale != null allows the field to correctly refresh its error message to the active locale upon state restoration or when a Localizations widget is dynamically introduced.
if (locale != _locale && widget.enabled && hasError) {
_validate();
}|
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
65a1d45 to
b1fb24e
Compare
|
Rebased onto current master and pushed a follow-up so Gold and presubmit can run on a fresh head. The follow-up addresses the review note about restored errors. Locally: The push cleared the |
A restored error is already visible before any previous locale is recorded, so the first dependency change has to refresh it too.
b1fb24e to
64b61a2
Compare
|
Rebased onto current master (
New head is |
Updates
FormFieldStateto observe locale changes and rerun the validator only when an enabled field already displays an error. This refreshes localized validation messages without enabling automatic validation for untouched fields.Fixes #143729.
Tests:
./bin/flutter test packages/flutter/test/widgets/form_test.dart./bin/flutter analyze --no-pub packages/flutterPre-launch Checklist
///).