getDescriptionForNumber method

String getDescriptionForNumber(
  1. PhoneNumber number,
  2. Locale languageCode, [
  3. String? userRegion
])

As per getDescriptionForValidNumber(PhoneNumber, Locale, String) but explicitly checks the validity of the number passed in.

number the phone number for which we want to get a text description languageCode the language code for which the description should be written userRegion the region code for a given user. This region will be omitted from the description if the phone number comes from this region. It should be a two-letter upper-case CLDR region code. returns a text description for the given language code for the given phone number, or empty string if the number passed in is invalid or could belong to multiple countries

Implementation

String getDescriptionForNumber(PhoneNumber number, Locale languageCode,
    [String? userRegion]) {
  if (userRegion == null) {
    PhoneNumberType numberType = _phoneUtil.getNumberType(number);
    if (numberType == PhoneNumberType.unknown) {
      return "";
    } else if (!_phoneUtil.isNumberGeographical(
        phoneNumberType: numberType,
        countryCallingCode: number.countryCode)) {
      return _getCountryNameForNumber(number, languageCode);
    }
    return getDescriptionForValidNumber(number, languageCode);
  } else {
    PhoneNumberType numberType = _phoneUtil.getNumberType(number);
    if (numberType == PhoneNumberType.unknown) {
      return "";
    } else if (!_phoneUtil.isNumberGeographical(
        phoneNumberType: numberType,
        countryCallingCode: number.countryCode)) {
      return _getCountryNameForNumber(number, languageCode);
    }
    return getDescriptionForValidNumber(number, languageCode, userRegion);
  }
}