country_code 0.1.1

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)[https://en.wikipedia.org/wiki/ISO_3166-1#Reserved_and_user-assigned_code_elements]

Usage #

import 'package:country_code/country_code.dart';

var code = CountryCode.tryParse("US");
if (code == CountryCode.US) {
  print(code.alpha2);
  print(code.alpha3);
  print(code.numeric);
}

(See more examples)[https://github.com/denixport/dart.country/tree/master/example]

Bugs and feature requests #

Please file feature requests and bugs at the issue tracker.

1.0.0 #

example/example.dart

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 = CountryCode.values.map<String>((c) => c.alpha2).join(", ");
  print(list);

  // 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:


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
53
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
99
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

We analyzed this package on Aug 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:country_code/country_code.dart.

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.

Dependencies

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