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

PhoneNumber().parse always returns first matching country for countries having same dial code number in Android. iOS working as expected. #118

Open WaseemAbbasi22 opened 10 months ago

WaseemAbbasi22 commented 10 months ago

Is there an existing issue for this?

Package/Plugin version

2.0.1

Platforms

Flutter doctor

[✓] Flutter (Channel stable, 3.10.4, on macOS 13.2.1 22D68 darwin-x64, locale en-GB)) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) [✓] Xcode - develop for iOS and macOS (Xcode 14.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.1) [✓] VS Code (version 1.78.2) [✓] Connected device (1 available) [✓] Network resources

Minimal code example

try { PhoneNumber phoneNumber = await PhoneNumberUtil().parse("+16045551234" ); print('result phone i got is ${resultPhone.regionCode}'); print('result phone2 i got is ${resultPhone.e164}'); } catch (e) { print('exception i got is $e'); return null; }

Current Behavior

await plugin.parse("+16045551234" ); always returns US as country it's same with other countries as well having the same country code i read the previous issues it's stated that it's fixed but still have the same issue on andriod

Expected Behavior

await PhoneNumberUtil().parse("+16045551234" ); should returns CA

Steps To Reproduce

Try parsing +16045551234 on Android only. Ios works as expected

Aditional information

This fix is only need for Android. For iOS it is working properly.

Previously Region Code was parsed using getRegionCodeForCountryCode() function but the country code for US and Canada is same '+1' so it always returned 'US'.

In updated code it uses getRegionCodeForNumber() function that gives accurate Region code which considers whole phone number. So it returns right Region code. this is the prevous issue fixes but it's still have the same problem in latest version