getCountry static method
Implementation
static Country getCountry(String mobileNumber) {
if (mobileNumber == "") {
throw NumberTooShortException();
}
final validMobileNumber = RegExp(r'^[+0-9]*[0-9]*$');
if (!validMobileNumber.hasMatch(mobileNumber)) {
throw InvalidCharactersException();
}
if (mobileNumber.startsWith('+')) {
return countries.firstWhere((country) => mobileNumber
.substring(1)
.startsWith(country.dialCode + country.regionCode));
}
return countries.firstWhere((country) =>
mobileNumber.startsWith(country.dialCode + country.regionCode));
}