I am building a flutter app and I am asking the user to enter their phone number to get started with signup on the landing page just after the splash screen. I do not wish to ask location permission at this stage because I feel it will affect the user’s experience.
I had a look at the Telegram and Twitter apps and noticed they are detecting the dialling code even without asking for android permissions.
I am assuming they get the users country and then based on that display the dialling code. But how do they get the country and is it legal to get the country code without asking for user’s permission?
2
Answers
I guess from your ISP/IP address?
There are API’s available that can guess the country and more based on IP.
Some ISP’s are also only available in certain countries and they have a fixed range of IP addresses.
What I suggest to you is to import this package to your pubspec.yaml:
https://pub.dev/packages/intl
Then in Your code simply call:
It will get the country code of the device locale.
Didn’t tested yet, but this method should work, enjoy 🙂