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

canopas_country_picker のカバー
パッケージ詳細v0.0.10

canopas_country_picker

検索機能付きの、国またはダイヤルコードを選択するためのシンプルでカスタマイズ可能なFlutter国選択ツール。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
427
いいね数
18
Pub ポイント
150

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

flutter pub add canopas_country_picker

パッケージ概要

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

国またはそのダイヤルコードを選択するためのシンプルでカスタマイズ可能なFlutterパッケージで、組み込みの検索機能を備えています。国選択が必要なフォームにおけるユーザー体験を向上させるために設計されており、Android、iOS、Web、macOS、Windows、Linuxなど複数のプラットフォームをサポートしています。ピッカーは軽量で、簡単に統合でき、開発者がアプリのニーズに応じて外観や動作をカスタマイズできるようになっています。

用途

  • 国選択付きのユーザー登録
  • 国コード付き電話番号入力
  • 国際フォームフィールド
  • 旅行または配送先住所の収集
  • 国名の多言語対応

主な機能

  • 検索可能な国リスト
  • カスタマイズ可能な UI
  • ダイヤルコードをサポートしています
  • クロスプラットフォーム互換性
  • 軽量で高速
  • Flutter フォームとの簡単な統合

適している対象

  • 国選択を必要とするモバイルおよびウェブアプリ
  • 国際ユーザーをターゲットにしたアプリ
  • 電話番号の入力を必要とするフォーム
  • 簡単な国ピッカーを探している開発者
  • 最小限の依存関係を持つプロジェクト

注意事項

  • 事前に定義された国データに限定
  • リアルタイムの国別更新なし
  • カスタマイズには追加のスタイル設定知識が必要になる場合があります
  • 位置情報機能を含んでいません
  • 新しい国を追加するには手動での更新が必要になる場合があります

元の README

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

A Simple, Customizable Flutter Country picker for picking a Country or Dialing code with Search functionality.

Preview

How to use

If you want to show the country picker bottom sheet, use:

CountryCode? code = await showCountryCodePickerSheet(context: context);

If you want to show the country picker dialog, use:

CountryCode? code = await showCountryCodePickerDialog(context: context);

If you want to show the country list as a UI component, use the CountryCodeSelector widget:

CountryCodeSelector(
   onCountryCodeTap: (CountryCode code) {
      /// Specify country code tap event
   },
    //Note: Cannot provide both onCountryCodeTap and codeBuilder, as onCountryCodeTap will not work if you have provided codeBuilder.
)

How to get a country code from the country alpha-2:,

CountryCode code = CountryCode.getCountryCodeByAlpha2(
    countryAlpha2Code:"IN", // its case-insensitive you can use both IN or in
);

You can use await Alpha2CountryCode,getCurrentCountryCode() to obtain the current alpha-2 code:

String countryAlpha2Code = await Alpha2CountryCode.getCurrentCountryCode();

CountryCode code = CountryCode.getCountryCodeByAlpha2(
  countryAlpha2Code: countryAlpha2Code,
);

Note: Using await Alpha2CountryCode.getCurrentCountryCode() will return the current country alpha-2 code based on the IP location from the 'http://ip-api.com/json/' API.


You can also get the current country alpha-2 code based on the user's device region, using PlatformDispatcher locale.

CountryCode code = CountryCode.getCountryCodeByAlpha2(
    countryAlpha2Code: WidgetsBinding.instance.platformDispatcher.locale.countryCode, 
    /// if you have context, use View.of(context).platformDispatcher.locale.countryCode
);

Note: WidgetsBinding and View.of(context) are provided by the Flutter SDK.


How to get a country code from the country dial code,

CountryCode code = CountryCode.getCountryCodeByDialCode(
    dialCode: "+91",
);

Note: Instead of using a dial code, which can be shared by multiple countries, we recommend using the alpha-2 code.


How to get a country codes from the country dial code,

List<CountryCode> code = CountryCode.getCountryCodesByDialCode(
    dialCode: "+47",
);

If you want to show the localized country name, use:

String? l10nCountryName = countryCode.localizedName("en");

Customizations

For customizations, we are providing the CustomizationBuilders class to customize each section.

customizationBuilders: CustomizationBuilders(
  codeBuilder: (CountryCode code) {
    // Return something to change the country list item UI.
    // Note: onCountryCodeTap will be overridden by codeBuilder in customizationBuilders.

   // If want to do some customization in default country code view, you can use
    return DefaultCountryCodeListItemView(
      onCountryCodeTap: () {},
      code: code,
      locale: 'US', // To show a localized country name,
    );
  },
  
  codeSeparatorBuilder: (BuildContext context, int index) {
    // Return something to add a separator between country codes.
    return const SizedBox(); // Default
  },
  
  countryListBuilder: (List<CountryCode> codes, ScrollController? controller) {
    // Return something to customize the country list
  },
  
  textFieldBuilder: (void Function(String)? filter) {
    // Return the search text field widget
    //
    // If you want to do some customization in the default text field, you can use
    return DefaultCountryCodeFilterTextField(
      filter: filter,
    );

    // Use filter(searchText); to update the country code list.
  },
),

Bugs and Feedback

For bugs, feedback, questions and discussions please use the Github Issues.

Credits

Canopas Country Picker is owned and maintained by the Canopas team. You can follow us on Twitter at @canopassoftware for project updates and releases.

We regularly upload blogs on new topics, which you can read here.

カテゴリー

ソースリポジトリ

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