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

Add fromDialCode(String dialCode) #137

Merged
merged 1 commit into from
Mar 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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