Skip to main content

country_code 1.2.0 copy "country_code: ^1.2.0" to clipboard
country_code: ^1.2.0 copied to clipboard

Provides list of ISO 3166-1 country codes in enum-like class, as well as parsing and user-assigned code elements

List of ISO 3166-1 assigned country codes.

pub package License

Features #

  • ✅ ISO 3166-1 alpha-2. alpha-3, and numeric country codes in enum-like class
  • ✅ Parsing of country codes from string
  • ✅ Support for user-assigned code elements

Usage #

import 'package:country_code/country_code.dart';

// All ISO country codes are accessible as constants
print(CountryCode.US.alpha3); // USA

final code = CountryCode.tryParse('US');
if (code != null) {
  print(code.alpha2); // US
  print(code.alpha3); // USA
  print(code.numeric); // 840
}

See more examples

Updating country codes #

The ISO 3166-1 constants in lib/src/country_code.dart are generated from tool/iso3166.tsv. Only the code between the //GENERATED:START and //GENERATED:END markers is generated; the rest of the file is written by hand.

To add, change, or remove a country, edit tool/iso3166.tsv (rows are tab-separated: alpha-2, alpha-3, numeric, English short name, sorted by alpha-2 code) and regenerate:

dart run tool/generate.dart

dart run tool/generate.dart --check exits with an error if the generated code is out of date; the test suite runs the same check.

Bugs and feature requests #

Please file feature requests and bugs at the issue tracker.

20
likes
160
points
57.3k
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Provides list of ISO 3166-1 country codes in enum-like class, as well as parsing and user-assigned code elements

Repository (GitHub)
View/report issues

Topics

#country-codes #iso-3166-1

License

MIT (license)

More

Packages that depend on country_code