Merge pull request #137 from m-Skolnick/master

Add `fromDialCode(String dialCode)`
This commit is contained in:
Salvatore Giordano authored and GitHub committed 2021-03-13 11:57:44 +01:00
commit 3568637992
1 file changed
+19 -1
+19 -1
View File
@@ -28,9 +28,27 @@ class CountryCode {
this.dialCode, this.dialCode,
}); });
@Deprecated('Use `fromCountryCode` instead.')
factory CountryCode.fromCode(String isoCode) { factory CountryCode.fromCode(String isoCode) {
return CountryCode.fromCountryCode(isoCode);
}
factory CountryCode.fromCountryCode(String countryCode) {
final Map<String, String> jsonCode = codes.firstWhere( 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, orElse: () => null,
); );