PhoneNumber constructor

PhoneNumber(
  1. Country? country,
  2. String? nationalNumber
)

Create PhoneNumber instance using given country and nationalNumber

Implementation

factory PhoneNumber(Country? country, String? nationalNumber) {
  if (country == null && nationalNumber == null) {
    return empty.clone();
  }

  final String normalizedNationalNumber = normalize(nationalNumber ?? '');

  return PhoneNumber._(
    country: country,
    nationalNumber: normalizedNationalNumber,
    formattedNumber: country == null
        ? normalizedNationalNumber
        : '+${country.prefix}$normalizedNationalNumber',
    isValid:
        country?.isValidNationalNumber(normalizedNationalNumber) ?? false,
  );
}