toCCPhoneNumber method

String toCCPhoneNumber({
  1. Locale locale = const Locale('id'),
  2. String? customCode,
})

Mengubah nomor lokal menjadi format dengan kode negara. Contoh: '0812xxxxxxx' → '62812xxxxxxx'

Implementation

String toCCPhoneNumber({Locale locale = const Locale('id'), String? customCode}) {
  final normalized = _normalize(this);
  final cc = customCode ?? _countryCodeByLocale[locale.languageCode.toLowerCase()] ?? '62';

  if (normalized.startsWith(cc)) return normalized;

  if (normalized.startsWith('0')) {
    return cc + normalized.substring(1);
  }

  return cc + normalized;
}