Skip to content

fix: move the length limit when the controller changes country - #366

Open
KuljeetSinghXDA wants to merge 1 commit into
cedvdb:mainfrom
KuljeetSinghXDA:fix/limit-length-country-change
Open

KuljeetSinghXDA wants to merge 1 commit into
cedvdb:mainfrom
KuljeetSinghXDA:fix/limit-length-country-change

Conversation

@KuljeetSinghXDA

Copy link
Copy Markdown
Contributor

With shouldLimitLengthByCountry: true the maximum length is computed in initState and after a country is picked in the selector. When the controller changes the country itself, the old length stays and the text field cuts valid digits.

final controller = PhoneController(
  initialValue: PhoneNumber.parse('+33', destinationCountry: IsoCode.FR),
);
// France allows 9 digits
controller.changeCountry(IsoCode.US); // the United States allows 10
// type 4165551234
controller.value.nsn; // '416555123' before this change

The 10th digit is dropped by LimitMaxLengthFormatter because it still holds the French limit.

  • The controller listener now recomputes _maxValidLength before the value is synced to the form field.
  • Added a widget test that changes the country through the controller and then types a 10 digit number. It fails on main with nsn: 416555123.

Checks run locally:

dart analyze lib/src/phone_form_field_state.dart test/phone_form_field_test.dart
No issues found!

dart format --output=none --set-exit-if-changed lib/src/phone_form_field_state.dart test/phone_form_field_test.dart
Formatted 2 files (0 changed)

flutter test
00:03 +83: All tests passed!

Checklist:

  • version bumped to 12.0.3 and CHANGELOG entry added
  • tests added

@github-actions

Copy link
Copy Markdown

Accepted: ready to merge

Fixes national number truncation by updating the length limit when the controller changes the selected country

Merging stays manual here: this repository does not merge automatically.


Written by a model reading the diff against .github/agent/review-prompt.md. The Tests workflow is the authority on whether the change works; a maintainer decides whether it belongs. Pushing to the branch updates this comment.

@github-actions github-actions Bot added the ai:accepted Read by the review bot: in scope and ready to merge label Nov 16, 2026
With shouldLimitLengthByCountry enabled the maximum length was computed
in initState and after a country was picked in the selector. When the
controller changed the country (changeCountry or an assigned value) the
old limit stayed. The text field then cut digits that are valid for the
new country, for example a 10 digit US number typed after switching from
France was reduced to 9 digits.

The controller listener now recomputes the limit before the value is
synced to the form field.
@KuljeetSinghXDA

Copy link
Copy Markdown
Contributor Author

Same version fix as #365, thanks for flagging it. Bumped pubspec.yaml to 12.0.4 and added a ## [12.0.4] CHANGELOG.md entry for the length-limit fix, rebased onto current main (e8cc9b9). flutter test 85 passed, dart analyze clean. Whichever of #365/#366 you merge first releases 12.0.4; I will bump the other to the next patch right after.

@KuljeetSinghXDA
KuljeetSinghXDA force-pushed the fix/limit-length-country-change branch from 5142d78 to e2136a5 Compare November 18, 2026 12:38

This branch has not been deployed

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

Labels

ai:accepted Read by the review bot: in scope and ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant