removeCountryCode method
Implementation
String removeCountryCode(
String? countryCode, Country selectedCountry, List<Country> countryList) {
String number = this;
debugPrint("number: $number");
if (countryCode == null && number.startsWith('+')) {
number = number.substring(1);
// parse initial value
selectedCountry = countries.firstWhere(
(country) => number.startsWith(country.fullCountryCode),
orElse: () => countryList.first);
debugPrint("selectedCountry: $selectedCountry");
// remove country code from the initial number value
number = number.replaceFirst(
RegExp("^${selectedCountry.fullCountryCode}"), "");
return number;
} else {
selectedCountry = countryList.firstWhere(
(item) => item.code == (countryCode ?? 'IN'),
orElse: () => countryList.first);
// remove country code from the initial number value
if (number.startsWith('+')) {
number = number.replaceFirst(
RegExp("^\\+${selectedCountry.fullCountryCode}"), "");
} else {
number = number.replaceFirst(
RegExp("^${selectedCountry.fullCountryCode}"), "");
}
return number;
}
}