add fromCountryCode

This commit is contained in:
Micaiah
2021-02-17 13:03:57 -07:00
parent 0fe203e8ff
commit a1ff28d314

View File

@@ -28,9 +28,27 @@ class CountryCode {
this.dialCode,
});
@Deprecated('Use `fromCountryCode` instead.')
factory CountryCode.fromCode(String isoCode) {
return CountryCode.fromCountryCode(isoCode);
}
factory CountryCode.fromCountryCode(String countryCode) {
final Map<String, String> jsonCode = codes.firstWhere(
(code) => code['code'] == isoCode,
(code) => code['code'] == countryCode,
orElse: () => null,
);
if (jsonCode == null) {
return null;
}
return CountryCode.fromJson(jsonCode);
}
factory CountryCode.fromDialCode(String dialCode) {
final Map<String, String> jsonCode = codes.firstWhere(
(code) => code['dial_code'] == dialCode,
orElse: () => null,
);