formatPhoneNumber function

String formatPhoneNumber({
  1. required String countryCode,
  2. required String phoneNumber,
})

Implementation

String formatPhoneNumber(
    {required String countryCode, required String phoneNumber}) {
  final String _countryCode =
      !countryCode.startsWith('+') ? '+$countryCode' : countryCode;

  if (_countryCode == '+1') {
    return '$countryCode$phoneNumber';
  }

  final String _phoneNumber =
      phoneNumber.startsWith('0') ? phoneNumber.substring(1) : phoneNumber;

  return '$_countryCode$_phoneNumber';
}