Skip to content
This repository has been archived by the owner on Jan 27, 2024. It is now read-only.

Formatter: format numbers without country codes #105

Open
1 task done
andr2k opened this issue May 30, 2023 · 0 comments
Open
1 task done

Formatter: format numbers without country codes #105

andr2k opened this issue May 30, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@andr2k
Copy link

andr2k commented May 30, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Package/Plugin version

2.0.0

What you'd like to happen

Let's start with an example: we have a text field with a prefix, and the prefix contains the country code. The prefix is "+1", and the number is "123 456 78 90". the user enters the number without the country code, the country code is known.

Since we already can supply the formatter with the locale, it can lookup the country code. Consequently, an ability to format the number which does not include the code seems to be logical in such a scenario

Possibly, we could specify which parts of the phone number are included in the user-entered string. Something like that:


final _phoneController = PhoneNumberEditingController(
    PhoneNumberUtil(),
    behavior: PhoneInputBehavior.strict,
    locale: 'US',
    staticNumberParts: [
        PhoneParts.plusSign, // optional
        PhoneParts.countryCode(), // // required, can be "static" or "entered"; the code is obtained from the locale
    ],
    enteredNumberParts: [
        PhoneParts.areaCode(), // required, can be "static" or "entered"
    ],
);

When areaCode is known:

final _phoneController = PhoneNumberEditingController(
    PhoneNumberUtil(),
    behavior: PhoneInputBehavior.strict,
    locale: 'US',
    staticNumberParts: [
        PhoneParts.plusSign, // optional
        PhoneParts.countryCode(), // required, can be "static" or "entered"; the code is obtained from the locale
        PhoneParts.areaCode('123'), // required, can be "static" or "entered"
    ],
        

);

Any workarounds here?



### Alternatives you've considered

_No response_

### Aditional information

_No response_
@andr2k andr2k added the enhancement New feature or request label May 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant