fix: #1484 autoValidateMode breaks invalidate method#1506
fix: #1484 autoValidateMode breaks invalidate method#1506majumdersubhanu wants to merge 6 commits intoflutter-form-builder-ecosystem:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1506 +/- ##
==========================================
- Coverage 91.06% 90.85% -0.22%
==========================================
Files 21 21
Lines 851 853 +2
==========================================
Hits 775 775
- Misses 76 78 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
deandreamatias
left a comment
There was a problem hiding this comment.
On issue related, had this steps to reproduce, but I can't see this flow in your video
tap Signup button once to set autovalidateMode = onUserInteraction. and then fill the form tap signup button again.
Please can create a video following this steps? Thanks!
| @override | ||
| bool validate({ | ||
| bool clearCustomError = true, | ||
| bool clearCustomError = false, |
There was a problem hiding this comment.
This is a breaking change. Need to add some advice for developers that use this method.
Maybe implement some dart fix (https://github.com/flutter-form-builder-ecosystem/flutter_form_builder/blob/main/lib/fix_data.yaml)
There was a problem hiding this comment.
@deandreamatias I've updated the video to do the exact steps to reproduce, please have a look, I'll add the dart fix ASAP.
| /// In previous versions, calling `validate()` would automatically clear any custom errors set via `invalidate()`. | ||
| /// Now, `validate()` does not clear custom errors by default. | ||
| /// If you want to clear the custom error when validating, you must explicitly pass `clearCustomError: true`. | ||
| /// |
There was a problem hiding this comment.
@deandreamatias I've added the breaking change notice to Dartdoc. I don't think implementing a dart fix will work here since data-driven fixes in Dart are only triggered when static analysis finds an issue such as a compilation error or deprecated usage.
- validate must exist, as it is an overridden method from Flutter's FormFieldState.
- We cannot deprecate it (which would trigger the analyzer).
- The change merely involves passing an optional named parameter (
clearCustomError: false), which is a valid syntax.
Since there's no compiler warning or error generated on existing, valid validate() calls, the static analysis tool won't flag anything and, ultimately, bypasses the file when a developer runs dart fix.
Connection with issue(s)
Close #1484
Close #1485
Solution description
Fixes an issue where
invalidate()calls were being cleared by framework validation whenautovalidateModewas active. It also introduces support for the new FlutterforceErrorTextproperty across the core library.Key Changes:
FormBuilderFieldStatePersistence Logic:clearCustomErrorinvalidate()fromtruetofalse. This prevents framework-triggered validation calls (which pass no arguments) from clearing manual errors.didChange()to explicitly clear_customErrorText. This ensures that manual errors are removed as soon as the user interacts with the field, maintaining a logical UX.forceErrorTextIntegration:forceErrorTexttoFormBuilderField,FormBuilderFieldDecoration, and core field constructors.FormFieldAPI (introduced in v3.24), allowing for declarative external error management.validate()andinvalidate()to reflect the updated behavior regarding custom error clearing.Code used for the demo
Screenshots or Videos
Screen.Recording.2026-04-15.004656.mp4
To Do