Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #137 from m-Skolnick/master
Browse files Browse the repository at this point in the history
Add `fromDialCode(String dialCode)`
  • Loading branch information
imtoori authored Mar 13, 2021
2 parents 0fe203e + a1ff28d commit 3568637
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/country_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'] == 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['code'] == isoCode,
(code) => code['dial_code'] == dialCode,
orElse: () => null,
);

Expand Down

0 comments on commit 3568637

Please sign in to comment.