Skip to content

fix: keep national digits that collide with the country calling code - #365

Merged
cedvdb merged 1 commit into
cedvdb:mainfrom
KuljeetSinghXDA:fix/national-calling-code-collision
Nov 18, 2026
Merged

cedvdb merged 1 commit into
cedvdb:mainfrom
KuljeetSinghXDA:fix/national-calling-code-collision

Conversation

@KuljeetSinghXDA

Copy link
Copy Markdown
Contributor

Typing a national number whose first digits equal the selected country's calling code loses those digits.

final controller = PhoneController(
  initialValue: const PhoneNumber(isoCode: IsoCode.NO, nsn: ''),
);
controller.changeNationalNumber('4705555');
print(controller.value.nsn); // '05555' before this change

changeNationalNumber passes the typed text to PhoneNumber.parse with the current country as destination. Without a +, the parser removes a leading country calling code when the whole input is invalid but the number without that code is valid. 4705555 becomes 47 + 05555.

  • The text field holds a national number, so the calling code is only read as an international prefix when the digits are too long for a national number of the selected country.
  • Pasting a full international number without + still works: 33612345678 in France gives 612345678.
  • A typed national prefix is still removed: 0612345678 in France gives 612345678.
  • Added three widget tests for these three cases. The first test fails on main with nsn: 05555.

Closes #345

Checks run locally:

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

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

flutter test
00:03 +85: 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 typed national numbers losing leading digits when they match the country calling code

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
@cedvdb

cedvdb commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Hello, when i merge a pr, the package is released, so since i merged your previous PR, the version in this one is wrong

can you change pubspec and changelog

PhoneController.changeNationalNumber always parsed the typed text with
PhoneNumber.parse and the current country as destination. When the input
has no '+', the parser removes a leading country calling code if the whole
input is invalid but the number without that code is valid. Typing
'4705555' in Norway therefore stored nsn '05555'.

The text field holds a national number, so the calling code is only read as
an international prefix when the digits are too long for a national number
of the selected country. This keeps pasted international numbers working
for example '33612345678' in France.

Closes cedvdb#345
@KuljeetSinghXDA

Copy link
Copy Markdown
Contributor Author

Good catch, thanks! Since #364 released 12.0.3, this branch now bumps pubspec.yaml to 12.0.4 and adds a ## [12.0.4] entry to CHANGELOG.md for the calling-code fix. Rebased onto current main (e8cc9b9) in the same push, so the conflict is gone. flutter test 87 passed, dart analyze clean.

If you merge #366 first instead, tell me and I will bump this one to the next patch so the release stays in order.

@KuljeetSinghXDA
KuljeetSinghXDA force-pushed the fix/national-calling-code-collision branch from f8fe0bc to c876a85 Compare November 18, 2026 12:37
@cedvdb
cedvdb merged commit f67fd4c into cedvdb:main Nov 18, 2026
1 of 2 checks passed
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.

PhoneController silently drops digits when typed NSN collides with current country's calling code

2 participants