fromDialCode static method
Gets CountryCode based on the given dial code.
Returns null
if not found.
Implementation
static CountryCode? fromDialCode(String? dialCode) {
if (dialCode == null) return null;
var formattedDC = dialCode;
if (!dialCode.startsWith('+')) formattedDC = '+$formattedDC';
final allCountryCodes = codes.map(CountryCode.fromMap).toList();
final index = allCountryCodes.indexWhere((c) => c.dialCode == formattedDC);
if (index == -1) return null;
return allCountryCodes[index];
}