Skip to content

fix: support dynamic function callbacks in equal/notEqual validators#163

Open
GhagSagar23 wants to merge 2 commits into
flutter-form-builder-ecosystem:mainfrom
GhagSagar23:fix/issue-63
Open

fix: support dynamic function callbacks in equal/notEqual validators#163
GhagSagar23 wants to merge 2 commits into
flutter-form-builder-ecosystem:mainfrom
GhagSagar23:fix/issue-63

Conversation

@GhagSagar23

Copy link
Copy Markdown

Connection with issue(s)

Close #63

Solution description

This PR updates the EqualValidator and NotEqualValidator classes to support dynamic comparison targets.

When you pass an argument to these validators (e.g., FormBuilderValidators.equal(password)), it is evaluated once during the parent widget's build tree execution. If the target field changes later (such as a password field during registration), the confirmation field's validator remains stuck on the stale initial value unless a full state rebuild is triggered.

Changes:

  1. Modified EqualValidator and NotEqualValidator to inspect if the comparison value is a Function. If it is, the validator evaluates it dynamically at validation runtime (using (value as Function)()) instead of statically.
  2. Extracted the resolution check to a private getter _resolvedValue and refactored validation methods using expression bodies.
  3. Added type annotations to satisfy the strict static analyzer rules of the package.
  4. Added new test suites in test/src/core/equal_validator_test.dart and test/src/core/not_equal_validator_test.dart confirming dynamic callbacks validate properly when comparison targets are updated.

Screenshots or Videos

(Not applicable — pure logic / functional package change)

To Do

  • Read contributing guide
  • Check the original issue to confirm it is fully satisfied
  • Add solution description to help guide reviewers
  • Add unit test to verify new or fixed behaviour
  • If apply, add documentation to code properties and package readme

Test Verification Output

All 984 unit tests passed successfully under static analyzer rules (fvm flutter analyze and fvm flutter test).

Click to expand unit test run logs
Analyzing form_builder_validators-fix-63...                     
No issues found! (ran in 2.2s)

00:01 +121: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/equal_validator_test.dart: EqualValidator - should return null if the value is equal to the specified value
00:01 +122: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/equal_validator_test.dart: EqualValidator - should return error if the value is not equal to the specified value
00:01 +123: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/equal_validator_test.dart: EqualValidator - should return null if the numeric value is equal to the specified value
00:01 +124: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/equal_validator_test.dart: EqualValidator - should return error if the numeric value is not equal to the specified value
00:01 +125: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/equal_validator_test.dart: EqualValidator - should return error if the value is null and null check is enabled
00:01 +126: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/equal_validator_test.dart: EqualValidator - should return null if the value is null and null check is disabled
00:01 +127: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/equal_validator_test.dart: EqualValidator - should return null if the value is empty and null check is disabled
00:01 +128: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/equal_validator_test.dart: EqualValidator - should return error if the value is empty and null check is enabled
00:01 +129: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/equal_validator_test.dart: EqualValidator - should return custom error message if the value is not equal to the specified value
00:01 +130: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/equal_validator_test.dart: EqualValidator - should support dynamic function callbacks for comparison value
00:02 +162: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/not_equal_validator_test.dart: NotEqualValidator - should return null if the value is not equal to the specified value
00:02 +165: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/not_equal_validator_test.dart: NotEqualValidator - should return null if the value is null and null check is disabled
00:02 +166: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/not_equal_validator_test.dart: NotEqualValidator - should return null if the value is null and null check is disabled
00:02 +169: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/not_equal_validator_test.dart: NotEqualValidator - should return null if the integer value is not equal to the specified value
00:02 +171: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/not_equal_validator_test.dart: NotEqualValidator - should return errorText if the integer value is equal to the specified value
00:02 +172: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/not_equal_validator_test.dart: NotEqualValidator - should return errorText if the integer value is equal to the specified value
00:02 +175: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/not_equal_validator_test.dart: NotEqualValidator - should return errorText if the double value is equal to the specified value
00:02 +177: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/not_equal_validator_test.dart: NotEqualValidator - should return null if the list value is not equal to the specified value
00:02 +179: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/not_equal_validator_test.dart: NotEqualValidator - should return errorText if the list value is equal to the specified value
00:02 +180: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/not_equal_validator_test.dart: NotEqualValidator - should return errorText if the list value is equal to the specified value
00:02 +181: /Users/ghag23/Community/form_builder_validators-fix-63/test/src/core/not_equal_validator_test.dart: NotEqualValidator - should support dynamic function callbacks for comparison value
...
00:13 +984: All tests passed!

  support dynamic function callbacks for comparison value in equal/notEqual validators
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.21%. Comparing base (986934a) to head (99f7077).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #163   +/-   ##
=======================================
  Coverage   99.20%   99.21%           
=======================================
  Files          95       95           
  Lines        1012     1018    +6     
=======================================
+ Hits         1004     1010    +6     
  Misses          8        8           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FormBuilderValidators.equal() do not update value to compare

1 participant