パッケージ、リポジトリ、アプリカテゴリを検索

country_codes のカバー
パッケージ詳細v3.3.0

country_codes

国コードは、特定のローカライゼーションに基づいて国に関する情報を提供するヘルパー パッケージです。ダイヤル コード、ISO 3166 コード(アルファ-2、アルファ-3)、国名などが含まれます。

AndroidiOSmacOS
30日間ダウンロード
3.4万
いいね数
134
Pub ポイント
150

パッケージをインストール

flutter pub add country_codes

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

国コードは、ローカライゼーションに基づく包括的な国情報(発信コード、ISO 3166アルファ-2およびアルファ-3コード、ローカライズされた国名など)を提供するFlutter/Dartパッケージです。異なる地域で一貫した国情報へのアクセスを可能にし、国際データの処理を簡素化します。軽量で、フォームや国選択ウィジェット、ローカライゼーションワークフローでの利用を想定して設計されています。Android、iOS、macOSプラットフォームをサポートしており、正確な国メタデータが必要なクロスプラットフォームアプリケーションに最適です。

用途

  • 国際電話番号入力
  • フォーム内の国選択
  • 国名のローカライズ
  • ISOコードを使用したデータ検証
  • 国ピッカーのウィジェットを構築する

主な機能

  • 複数の国識別子をサポートしています
  • ローカライズされた国名
  • ダイヤルコード検索
  • ISO 3166 アルファ-2およびアルファ-3コード
  • クロスプラットフォーム互換性

適している対象

  • 国データが必要なアプリ
  • 国選択付きのフォーム入力
  • 国際化機能
  • グローバルユーザーを持つモバイルアプリ
  • 国選択ツールを開発する開発者

注意事項

  • ロケールのフォールバックを手動で処理する必要があります
  • 組み込みのUIコンポーネントなし
  • 静的国別データに限定
  • タイムゾーンや通貨情報は含まれません
  • 正しいロケール設定の構成に依存しています

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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(); // Optionally, you may provide a `Locale` to get countrie's localizadName

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

final CountryDetails details = CountryCodes.detailsForLocale();
print(details.alpha2Code); // Displays alpha2Code, for example US.
print(details.dialCode); // Displays the dial code, for example +1.
print(details.name); // Displays the extended name, for example United States.
print(details.localizedName); // Displays the extended name based on device's language (or other, if provided on init)
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 = CountryCodes.detailsForLocale(Localization.localeOf(context));

print(details.alpha2Code); // Displays alpha2Code, displays PT.
print(details.dialCode); // Displays the dial code for PT, +351.
print(details.name); // 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.

TextFormField(
  keyboardType: TextInputType.phone,
  inputFormatters: [DialCodeFormatter()],
);

Example app

Example

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.

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト