feat: add showCountryCode parameter to PhoneInputFormatter#182
Open
bernardoveras wants to merge 2 commits intocaseyryan:masterfrom
Open
feat: add showCountryCode parameter to PhoneInputFormatter#182bernardoveras wants to merge 2 commits intocaseyryan:masterfrom
bernardoveras wants to merge 2 commits intocaseyryan:masterfrom
Conversation
Add a showCountryCode flag (default: true) to PhoneInputFormatter, formatAsPhoneNumber, and isPhoneValid for API consistency. When set to false, the formatted output displays only the local part of the phone number (e.g. '(11) 99999-9999' instead of '+55 (11) 99999-9999') while the unmasked getter always returns the full international number. Also fixes a latent negative-offset assertion crash in formatEditUpdate by clamping selectionEnd, and extracts the duplicated strip-and-trim logic into a private _resolveCountryCodeDisplay helper.
…arameter feat: add showCountryCode parameter to PhoneInputFormatter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
showCountryCodeparameter (default:true) toPhoneInputFormatter,formatAsPhoneNumber, and theisFilled/unmaskedgetters.false, the formatted output displays only the local portion of the number (e.g.(11) 99999-9999) whileunmaskedalways returns the full international number (e.g.+5511999999999)._applyMaskandformatAsPhoneNumberinto a single private_resolveCountryCodeDisplayhelper.formatEditUpdateby clampingselectionEnd— this could trigger whenshowCountryCode: falseproduces a masked value shorter than the input and the cursor is positioned early in the text.Usage
Breaking changes
None.
showCountryCodedefaults totrue, preserving all existing behaviour exactly.Test plan
flutter test test/flutter_multi_formatter_test.dart— all existing tests pass; 9 newshowCountryCodetests added covering BR, US, partial input,unmaskedgetter,formatAsPhoneNumber,isPhoneValid, and thedefaultCountryCodecombination.flutter analyze lib/formatters/phone_input_formatter.dart— no issues.PhoneInputFormatter(showCountryCode: false)to aTextField, enter a Brazilian number (+5511999999999) and confirm display shows(11) 99999-9999whileformatter.unmaskedreturns+5511999999999.