acoutts / flutter_libphonenumber

Leverages libphonenumber to allow for asynchronous and synchronous formatting of phone numbers in Flutter apps. Includes a TextInputFormatter to allow real-time AsYouType formatting.
MIT License
60 stars 73 forks source link

Ability to recognize country when inserting a phone number #68

Open lukas-pierce opened 6 months ago

lukas-pierce commented 6 months ago

When code user provides autofillHints telephoneNumber iOS automatically suggests end user's phone from their contact card (Phone -> Contacts -> My Card)

TextFormField(
  autofillHints: const [
    AutofillHints.telephoneNumber,
  ],
  inputFormatters: [
    LibPhonenumberTextFormatter(
      country: libphonenumber.CountryManager().countries.firstWhere((c) => c.countryCode == 'AE')
    ),
  ],
  ...
)

In this case, the LibPhonenumberTextFormatter treats the prefix as part of the number and removes the ending. But it would be great if, when inserting, the country was automatically recognized and the appropriate mask was applied. You can see an example in this GIF

For these purposes I added dlibphonenumber package dependency. Which is a dart port of the google/libphonenumber original library

autofill-phone