country_code 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 84

List of ISO 3166-1 assigned country codes.

pub package Build Status

Features #

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

Usage #

import 'package:country_code/country_code.dart';

var code = CountryCode.tryParse("US");
if (code == CountryCode.US) {

(See more examples)[]

Bugs and feature requests #

Please file feature requests and bugs at the issue tracker.

1.0.0 #


import 'package:country_code/country_code.dart';

void main() {
  // All ISO country codes are accesible via constants
  print(CountryCode.US.alpha3); // -> USA
  print(CountryCode.US.numeric); // -> 840
  print(CountryCode.US.symbol); // -> 🇺🇸

  // The list of ISO-assigned codes are in CountryCode.values
  var list =<String>((c) => c.alpha2).join(", ");

  // You can statically access countries by alpha-2, alpha-3, or numeric code
  // That's also helpful to get other ISO codes for known code
  print(CountryCode.ofAlpha("US").alpha2); // -> US
  print(CountryCode.ofAlpha("USA").alpha2); // -> US
  print(CountryCode.ofNumeric(840).alpha2); // -> US

  // Always same values for the same country code is returned
  print(identical(CountryCode.ofAlpha("US"), CountryCode.US)); // -> true

  // You can also parse alpha-2, alpha-3, or numeric code
  print(CountryCode.parse("US").alpha2); // -> US
  print(CountryCode.parse("USA").alpha2); // -> US
  print(CountryCode.parse("840").alpha2); // -> US

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  country_code: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:country_code/country_code.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Maintenance suggestions

The package description is too short. (-1 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
pedantic ^1.0.0
test ^1.0.0