getRegionInfoFromPhoneNumber method Null safety

Future<PhoneNumber> getRegionInfoFromPhoneNumber(
  1. String phoneNumber,
  2. [String isoCode = '']
)

Returns PhoneNumber which contains region information about the phoneNumber and isoCode passed.

Implementation

static Future<PhoneNumber> getRegionInfoFromPhoneNumber(
  String phoneNumber, [
  String isoCode = '',
]) async {
  RegionInfo regionInfo = await PhoneNumberUtil.getRegionInfo(
      phoneNumber: phoneNumber, isoCode: isoCode);

  String? internationalPhoneNumber =
      await PhoneNumberUtil.normalizePhoneNumber(
    phoneNumber: phoneNumber,
    isoCode: regionInfo.isoCode ?? isoCode,
  );

  return PhoneNumber(
    phoneNumber: internationalPhoneNumber,
    dialCode: regionInfo.regionPrefix,
    isoCode: regionInfo.isoCode,
  );
}