flutter_libphonenumber icon indicating copy to clipboard operation
flutter_libphonenumber copied to clipboard

Facing issue in formatting number

Open arslankaleem7229 opened this issue 1 year ago • 1 comments

I am retrieving contacts from my phone and parsing it using formatNumberSync function to format phone number now I am facing an issue with country codes. Let suppose some of my contacts have country code in it and some contacts don't have country code in it. How you handle this thing? As the number being parsed it plain String lie "1234567890" or "+11234567980". Now how can I handle this thing.

Thanks!

arslankaleem7229 avatar Jun 20 '24 21:06 arslankaleem7229

It's a tricky thing. There's no real solution since you have to know the country code to correctly parse it. The best you can do is guess which is what the package tries to do.

A safe approach is to default to the device locale to get the country code, because you can reasonably assume local numbers to the device probably don't have the country code saved for most cases.

acoutts avatar Jun 20 '24 22:06 acoutts