separatePhoneAndDialCode function
Implementation
PhoneNumberDetails? separatePhoneAndDialCode(String phoneWithDialCode) {
Map<String, String> foundedCountry = {};
PhoneNumberDetails? phoneNumberDetails;
for (var country in CountriesConstant.allCountries) {
String dialCode = country["dial_code"].toString();
if (phoneWithDialCode.contains(dialCode)) {
foundedCountry = country;
}
}
if (foundedCountry.isNotEmpty) {
var dialCode = phoneWithDialCode.substring(
0,
foundedCountry["dial_code"]!.length,
);
var newPhoneNumber = phoneWithDialCode.substring(
foundedCountry["dial_code"]!.length,
);
log('{$dialCode, $newPhoneNumber}');
phoneNumberDetails = PhoneNumberDetails(dialCode: dialCode, phoneNumber: newPhoneNumber);
}
return phoneNumberDetails;
}