country_codes
3.3.0, released 2 years ago by miguelruivo.com
Provides country details, ISO codes, and dial codes based on localization.
What it does
Fetches region and country details such as ISO 3166 codes (alpha-2, alpha-3), dial codes, and country names based on a provided or device locale. It also includes a TextInputFormatter to handle dial codes dynamically in form fields.
AI-written summary of version 3.3.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to access country dial codes and ISO codes based on the device or custom locale.
- You are building phone number input forms that require automatic dial code formatting.
Skip it when
- You only need language and locale translations without country specific metadata.
- You need an exhaustive country picker widget out of the box (this is primarily a data helper package).
Strengths
- Provides localized country names and dial codes easily.
- Includes a built-in DialCodeFormatter for text form fields.
- Supports both device region detection and custom locales.
Weaknesses
- Requires manual initialization via CountryCodes.init() before use.
- Limited to basic country details and a single text input formatter.
Setup
- Kind
- Plugin (native code)
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
Must call await CountryCodes.init() before invoking package methods.
await CountryCodes.init();
final CountryDetails details = CountryCodes.detailsForLocale();
print(details.alpha2Code);
print(details.dialCode);
print(details.name);Alternatives
Packages that do the same job and could replace country_codes.
- sealed_countries
Provides compile-time constant data for world countries using sealed classes.
84Compare - phonecodes
Provides a list of countries with names, ISO codes, dial codes, flags, and currencies.
54Compare - l10n_languages
Provides CLDR-like translations for language names across 157 locales.
80Compare - l10n_currencies
Provides CLDR-like currency name translations for 149 locales in pure Dart with zero dependencies.
80Compare