flutter-form-builder-ecosystem / phone_number

Flutter plugin for parsing, formatting and validating international phone numbers.
https://pub.dev/packages/phone_number
BSD 3-Clause "New" or "Revised" License
81 stars 63 forks source link

countryCode returning dial code instead of ISO 1366 country code #71

Closed cybex-dev closed 2 years ago

cybex-dev commented 2 years ago

Environment

Package version: 0.12.0+2 (latest on pub.dev as of July 2022)

Flutter doctor ``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.0.1, on Arch Linux 5.18.7-arch1-1, locale en_US.UTF-8) [✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) [✓] Chrome - develop for the web [✓] Linux toolchain - develop for Linux desktop [✓] Android Studio (version 2021.2) [✓] IntelliJ IDEA Ultimate Edition (version 2021.3) [✓] Connected device (3 available) [✓] HTTP Host Availability • No issues found! ```
Code sample ```dart // random US number final hint = "+11234567890" // parse number into PhoneNumber object final phoneNumber = await PhoneNumberUtil().parse(hint); // extract country code print(phoneNumber.countryCode) // prints 1 instead of 'US' as documentation states ```

Description

Either documentation is incorrect or function is incorrect. Documentation states countryCode should return ISO 3166-1 alpha-2 codes like 'US', instead it returns the country's dialcode.

Documentation states

Expected behavior: phoneNumber.countryCode should return country code i.e. "US" or "ZA"

Current behavior: phoneNumber.countryCode returns country's dialing code i.e. "1" or "27"

Tested on US number and South African numbers.

ooglek commented 2 years ago

Seconding this -- agreed!

iamsahilsonawane commented 2 years ago

@cybex-dev @ooglek

The issue is now been fixed in this PR. Once it gets merged you can use:

phoneNumber.countryCode; // Ex: 1 or 27
phoneNumber.regionCode; // Ex: "US" or "ZA"

Sorry for the delay. Thanks for pointing out the issue!