feat: add asyncValidator support to FormBuilderField (#838) - #1514
feat: add asyncValidator support to FormBuilderField (#838)#1514GhagSagar23 wants to merge 5 commits into
Conversation
…ilder-ecosystem#838) Introduces an optional asyncValidator callback on FormBuilderField, validateAsync() on both FormBuilderFieldState and FormBuilderState, and saveAndValidateAsync() on FormBuilderState. - asyncValidator: Future<String?> Function(T?) runs after sync validation passes - Stale results are discarded via a request counter (_asyncValidationCount) - isValidating getter exposes loading state for UI spinners - didChange() and reset() clear async error state - Forwarded through FormBuilderFieldDecoration and FormBuilderTextField Closes flutter-form-builder-ecosystem#838
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1514 +/- ##
==========================================
+ Coverage 92.35% 93.45% +1.10%
==========================================
Files 21 21
Lines 863 948 +85
==========================================
+ Hits 797 886 +89
+ Misses 66 62 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
546b2a0 to
8a8844d
Compare
- Add test for `saveAndValidateAsync` and `autoScrollWhenFocusOnInvalid` in FormBuilder
- Add tests for exceptions thrown inside `asyncValidator` in FormBuilderField
- Add test for `validateAsync(clearCustomError: true)` clearing previous custom/async errors
- Add test for auto-scroll trigger when synchronous validation fails before async validation runs
|
Hi! Thanks for contribution
|
Hey @deandreamatias, both the points have been addressed in the latest commit. Can you please re-review this PR? |
|
This PR was flagged by our automated quality checks. If you're a genuine Common reasons for flagging:
We appreciate your contribution and apologize if this is a false positive! |
Genuine contributor here — not agent-generated. I picked up #838 because I needed async validation in a production app and the issue has been open since 2021. The implementation went through review with @deandreamatias already (added README docs and clarified the AutovalidateMode interaction per his feedback). Happy to answer any further questions. |
|
@GhagSagar23 could be share your production app? A link from Google Play or App Store could be enough |
Hi @deandreamatias, my app is not yet deployed on either of the stores. It still in development phase. |
|
So isn't a production app, yet, right? |
Not yet @deandreamatias |
Summary
Adds asynchronous validation support to
FormBuilderField, addressing #838.New API
asyncValidatorFormBuilderFieldFuture<String?> Function(T?)— runs after sync validation passesvalidateAsync()FormBuilderFieldStatevalidateAsync()FormBuilderStatesaveAndValidateAsync()FormBuilderStateisValidatingFormBuilderFieldStatetruewhile an async validator is in-flightDesign
validateAsync(), never auto-triggered on keystroke (avoids rebuild loops).didChange()clears async errors;reset()cancels in-flight validations.Usage
Tests
All 151 tests passed
Closes #838