getExampleNumberForNonGeoEntity method
Gets a valid number for the specified country calling code for a non-geographical entity.
countryCallingCode
the country calling code for a non-geographical entity.
getExampleNumberForNonGeoEntity returns a valid number for the
non-geographical entity. Returns null when the metadata does not contain
such information, or the country calling code passed in does not belong
to a non-geographical entity.
Implementation
PhoneNumber? getExampleNumberForNonGeoEntity(int countryCallingCode) {
PhoneMetadata? metadata =
getMetadataForNonGeographicalRegion(countryCallingCode);
if (metadata != null) {
PhoneNumberDesc? numberTypeWithExampleNumber = [
metadata.mobile,
metadata.tollFree,
metadata.sharedCost,
metadata.voip,
metadata.voicemail,
metadata.uan,
metadata.premiumRate,
].firstWhere(
(desc) => desc.hasExampleNumber(),
orElse: () => PhoneNumberDesc(),
);
if (numberTypeWithExampleNumber.isInitialized()) {
try {
return parse(
'+$countryCallingCode${numberTypeWithExampleNumber.exampleNumber}',
'ZZ');
} catch (e) {
return null;
}
}
}
return null;
}