getCountryDataByPhone static method
Implementation
static PhoneCountryData? getCountryDataByPhone(
String phone, {
int? substringLength,
}) {
if (phone.isEmpty) return null;
phone = phone.replaceAll('+', '');
substringLength = substringLength ?? phone.length;
if (substringLength < 1) return null;
var phoneCode = phone.substring(0, substringLength);
var rawData = _data.firstWhereOrNull(
(data) =>
toNumericString(
data['internalPhoneCode'],
allowAllZeroes: true,
) ==
phoneCode,
);
if (rawData != null) {
return PhoneCountryData.fromMap(rawData);
}
return getCountryDataByPhone(phone, substringLength: substringLength - 1);
}