Skip to content

fix(field): #1370 isDirty flag reset on initialValue #1507

Open
majumdersubhanu wants to merge 6 commits intoflutter-form-builder-ecosystem:mainfrom
majumdersubhanu:fix/1370-reset-dirty-order
Open

fix(field): #1370 isDirty flag reset on initialValue #1507
majumdersubhanu wants to merge 6 commits intoflutter-form-builder-ecosystem:mainfrom
majumdersubhanu:fix/1370-reset-dirty-order

Conversation

@majumdersubhanu
Copy link
Copy Markdown
Contributor

Connection with issue(s)

Close #1370

Solution description

  • Reset isDirty flag if the current value in a form field matches the defined initial value.
  • Corresponding tests

Screenshots or Videos

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

Copilot AI review requested due to automatic review settings April 22, 2026 09:14
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.82%. Comparing base (38a24f6) to head (3afd6f2).

Files with missing lines Patch % Lines
lib/src/form_builder_field.dart 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1507      +/-   ##
==========================================
- Coverage   90.85%   90.82%   -0.04%     
==========================================
  Files          21       21              
  Lines         853      861       +8     
==========================================
+ Hits          775      782       +7     
- Misses         78       79       +1     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes reported isDirty behavior so a field (and thus the form) is no longer considered dirty when its current value matches the configured initialValue, and prevents reset() from triggering recursive onChanged/reset() flows.

Changes:

  • Update FormBuilderFieldState dirty tracking to derive isDirty from value vs initialValue.
  • Adjust reset() ordering to clear dirty before emitting change notifications.
  • Add widget tests covering “return to initial value” and recursion/overflow scenarios.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/src/form_builder_field.dart Changes dirty calculation and reorders reset() to avoid re-entrant dirty state during callbacks.
test/src/form_builder_test.dart Adds a form-level test verifying FormBuilderState.isDirty clears when user returns to initial value.
test/src/form_builder_field_test.dart Adds field-level tests for isDirty clearing and a regression test intended to cover reset recursion behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/src/form_builder_field_test.dart
Comment thread lib/src/form_builder_field.dart
@majumdersubhanu
Copy link
Copy Markdown
Contributor Author

@deandreamatias could you please take a look at this PR?

@deandreamatias
Copy link
Copy Markdown
Collaborator

I need a time to take a look deeply on this, because can affect other parts of ecosystem.

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.

Internal field 'isDirty' flag is reset too late.

3 participants