분류, 패키지 및 저장소 검색

country_calling_code_kit 표지
패키지 상세v2.0.0

country_calling_code_kit

깃발, 이름 및 통화 코드와 함께 국가 코드를 선택할 수 있는 세련된 Flutter 패키지입니다. 사용자 정의 가능한 UI, 플랫폼 대응, 사용자 친화적입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
422
좋아요
1
Pub 점수
160

패키지 설치

flutter pub add country_calling_code_kit

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

깔끔한 플러터 패키지로 사용자가 국기, 국가 이름 및 통화 코드와 함께 국가 코드를 선택할 수 있습니다. 간편함과 커스터마이징을 위해 설계되었으며, Android, iOS, Web, macOS, Windows, Linux에서 깔끔하고 플랫폼 적응형 인터페이스를 제공합니다. 국제 전화번호 입력이 필요한 폼에 이상적이며, 최소한의 설정으로 원활한 사용자 경험을 보장합니다.

사용 사례

  • 국제 전화번호 입력
  • 국가 선택을 포함한 사용자 온보딩
  • 다중 지역 앱 로컬라이제이션
  • 문의 양식 개선
  • 여행 또는 글로벌 서비스 앱
  • 국가 코드가 필요한 인증 흐름

주요 기능

  • 통합 국가 깃발
  • 다이얼 코드 및 국가 이름 지원
  • 사용자 정의 가능한 UI 컴포넌트
  • 크로스 플랫폼 호환성
  • Flutter 폼과의 간편한 통합
  • 반응형이고 접근성 있는 디자인

적합한 대상

  • 글로벌 앱을 개발하는 개발자
  • 폼 중심 애플리케이션
  • 국제 사용자를 대상으로 하는 앱
  • 국가 선택이 필요한 모바일 및 웹 애플리케이션
  • 직관적인 입력을 우선시하는 사용자 경험 중심 개발자

고려 사항

  • 선택한 국가 데이터를 수동으로 처리해야 합니다
  • 국가 코드 및 국기 표시에 한정
  • 전화번호에 대한 내장 검증 없음
  • 다크 모드를 위해 추가적인 스타일링이 필요할 수 있습니다
  • 완전한 기능을 위해 외부 플래그 자산에 의존합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Country Calling Code Kit

A sleek, customizable Flutter package for picking country calling codes — complete with flags, country names, and dial codes. Present it as a dialog or a bottom sheet, tailor it to your app's design, and ship to every Flutter platform.

pub package license platforms

image1 image2 image3

Features

  • Dialog or bottom sheet — present the picker in whichever style fits your flow.
  • Automatic default country — detects the user's region from the device locale, no plugins or permissions required.
  • Built-in search — filter by country name, ISO code, or calling code.
  • Rich display — country flags, names, and dial codes in a clean, ready-to-use UI.
  • Highly customizable — text styles, colors, flag size, corner radii, dimensions, and shape.
  • Universal platform support — Android, iOS, Web, macOS, Linux, and Windows, with WebAssembly (WASM) compatibility.
  • Zero non-SDK dependencies — pure Dart and Flutter under the hood.

Installation

Add the package with the Flutter CLI:

flutter pub add country_calling_code_kit

Or add it to your pubspec.yaml manually:

dependencies:
  country_calling_code_kit: ^2.0.0

Then import it:

import 'package:country_calling_code_kit/country_calling_code_kit.dart';

Migrating to 2.0.0

Version 2.0.0 removes the native device_region dependency in favor of pure-Dart, locale-based detection. This makes the package WASM-compatible and available on all six platforms, but changes how the default country is resolved.

What changed: getDefaultCountry() now derives the region from the device/browser locale instead of the SIM card, and returns null when the locale has no region component (previously it fell back to the first country in the list).

What to do: provide your own fallback when the region can't be determined.

Future<void> loadDefaultCountry() async {
  // Before (1.x) — a non-null Country was effectively guaranteed:
  //   final Country country = (await getDefaultCountry())!;

  // After (2.0.0) — handle the nullable result explicitly:
  final Country country = await getDefaultCountry() ?? countries.first;
}

No other APIs changed. If you never called getDefaultCountry(), no migration is required.

Usage

Show a country picker dialog
Future<void> pickCountry(BuildContext context) async {
  final Country? country = await showCountryPickerDialog(context: context);

  if (country != null) {
    print('Name: ${country.name}'); // e.g. India
    print('Country code: ${country.countryCode}'); // e.g. in
    print('Calling code: ${country.callCode}'); // e.g. +91
  }
}
Show a country picker bottom sheet
Future<void> pickCountry(BuildContext context) async {
  final Country? country = await showCountryPickerModalSheet(context: context);

  if (country != null) {
    // Use the selected country.
  }
}
Detect the default country

Returns the [Country] matching the device's locale region, or null if it cannot be determined.

Future<void> loadDefaultCountry() async {
  final Country? defaultCountry = await getDefaultCountry();
  final Country country = defaultCountry ?? countries.first;
}
Look up a country by code
void findIndia() {
  final Country? india = getCountryByCountryCode(CountryCode.in_);
}
Access the full country list
void printCountries() {
  for (final country in countries) {
    print('${country.name} (${country.callCode})');
  }
}

Customization

Both showCountryPickerDialog and showCountryPickerModalSheet accept the following optional parameters:

Parameter Type Description
countryNameTextStyle TextStyle? Text style for country names.
countryCallCodeTextStyle TextStyle? Text style for calling codes.
imageSize Size? Size of the flag images (default 40 × 25).
splashColor Color? Splash color for list items.
hoverColor Color? Hover color for list items (web/desktop).
searchFilter List<Country> Function(String)? Custom search/filter logic.
preferredCountries List<CountryCode>? Countries pinned to the top of the list.
showCallCode bool Whether to show calling codes (default true).
search bool Whether to show the search bar (default true).
flagCornerRadius double? Corner radius for flag images (default 0).
itemBorderRadius double? Corner radius for each list item (default 10).
maxWidth double? Maximum width of the dialog/sheet.
maxHeight double? Maximum height of the dialog/sheet (default 80% / 85% of screen).
shape ShapeBorder? Shape border of the dialog/sheet (default rounded corners).

Example:

Future<void> pickCountry(BuildContext context) async {
  final country = await showCountryPickerModalSheet(
    context: context,
    preferredCountries: [CountryCode.us, CountryCode.gb, CountryCode.in_],
    showCallCode: true,
    flagCornerRadius: 4,
    itemBorderRadius: 12,
    maxWidth: 480,
    shape: const RoundedRectangleBorder(
      borderRadius: BorderRadius.vertical(top: Radius.circular(28)),
    ),
  );
}
Using the widget directly

For full control over layout, embed CountryPicker yourself instead of using the dialog/sheet helpers:

Widget buildPicker() {
  return CountryPicker(
    onSelected: (country) {
      // Handle selection.
    },
    preferredCountries: [CountryCode.us, CountryCode.gb],
    showCallCode: true,
  );
}

Data model

Each result is a Country:

Field Type Description
name String Full country name.
flag String Asset path to the country's flag image.
countryCode CountryCode ISO 3166-1 alpha-2 code (as an enum value).
callCode String International calling code (e.g. +1).

CountryCode is an enum of ISO 3166-1 alpha-2 codes. Values that collide with Dart keywords use a trailing underscore (for example CountryCode.in_). Use CountryCode.fromString('in') to parse a code and code.toString() to get its string form.

Example

A complete, runnable example is available in the /example directory.

import 'package:country_calling_code_kit/country_calling_code_kit.dart';
import 'package:flutter/material.dart';

class CountryPickerDemo extends StatefulWidget {
  const CountryPickerDemo({super.key});

  @override
  State<CountryPickerDemo> createState() => _CountryPickerDemoState();
}

class _CountryPickerDemoState extends State<CountryPickerDemo> {
  Country? country;

  @override
  void initState() {
    super.initState();
    _initCountry();
  }

  Future<void> _initCountry() async {
    country = await getDefaultCountry() ?? countries.first;
    if (mounted) setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Country Picker Demo')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            if (country != null) ...[
              Image.asset(country!.flag, width: 100, height: 60),
              const SizedBox(height: 16),
              Text('Name: ${country!.name}'),
              Text('Code: ${country!.countryCode.toString().toUpperCase()}'),
              Text('Call Code: ${country!.callCode}'),
              const SizedBox(height: 24),
            ],
            ElevatedButton(
              onPressed: () async {
                final selected =
                await showCountryPickerDialog(context: context);
                if (selected != null) {
                  setState(() => country = selected);
                }
              },
              child: const Text('Select Country'),
            ),
          ],
        ),
      ),
    );
  }
}

Resources

Credits

Inspired by and with credit to country_calling_code_picker.

Contributing

Contributions are welcome!

If this package helps you, please consider giving it a ⭐️ on GitHub and a 👍 on pub.dev.

License

Released under the MIT License.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.