country_codes 0.1.0

Country Codes #

Country Codes Build Status Buy me a coffee

Country codes package provides an easy to way to access country codes based on a provided Locale.

Usage #

There are two main ways to use this package.

1. Default by using device region #

This will allow you to fetch the region of the underlying platform and display the data accordingly. Very handy if you use along with the DialCodeFormatter to provide integration with dial codes formatter, on phone TextFormFields in a Form, for example.

Assuming an en-US region based revice.

await CountryCodes.init();

final Locale deviceLocale = CountryCodes.getDeviceLocale();
print(deviceLocale.languageCode); // Displays en
print(deviceLocale.countryCode); // Displays US

final CountryDetails details = CountryDetails.detailsForLocale();
print(details.alpha2Code); // Displays alpha2Code, for example US.
print(details.dialCode); // Displays the dial code, for example +1.
print(; // Displays the extended name, for example United States.

2. Use a custom Locale

This will use the provided Locale, which may not be related to the device's region but instead to the app supported languages.

For example, if your device is on US region but the app only supports PT, you'll get the following:

final CountryDetails details = CountryDetails.detailsForLocale(Localization.localeOf(context));

print(details.alpha2Code); // Displays alpha2Code, displays PT.
print(details.dialCode); // Displays the dial code for PT, +351.
print(; // Displays the extended name, Portugal.

Formatters #

DialCodeFormatter #

Currently there's only available TextInputFormatter which allows you to dynamically set the dial code dynamically on a TextFormField.

           inputFormatters: [DialCodeFormatter()],

Example app #


Getting Started #

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

[0.1.0] - 13/02/2020

  • Exposes device Locale (language and country code) instead of country only.

[0.0.6+2] - 12/02/2020

  • Updates dialCode() to receive the [locale] optionally instead of explictly null in order to retrieve the device's region dial code.

[0.0.6+1] - 03/02/2020

  • Replaces FutureOr<Locale> with Locale to make it explicitly synchronous when invoking getDeviceLocale()

[0.0.6] - 03/02/2020

  • Exposes device's Locale through getDeviceLocale() method.

[0.0.5] - 31/01/2020

  • Updates README

[0.0.4] - 31/01/2020

  • Adds default locale from device region when not provided. For this to work, please call CountryCodes.init() before invoking other methods.
  • Overall minor improvements.

[0.0.3] - 30/01/2020

  • Format

[0.0.2] - 30/01/2020

  • Adds license (MIT)

[0.0.1] - 30/01/2020

  • Initial release. Provides access to DialCodeFormatter for TextFormFields, alpha2Code, dialCode and name.


country_codes_example #

Demonstrates how to use the country_codes plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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

  country_codes: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support 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_codes/country_codes.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 Feb 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies