all_country_code 3.0.0+5 copy "all_country_code: ^3.0.0+5" to clipboard
all_country_code: ^3.0.0+5 copied to clipboard

A flutter package for country code picker with search and filter functionality.

Country Code Picker #

A Flutter package that provides a customizable country code picker with flags and search functionality. Easily integrate a user-friendly dropdown to select countries, complete with flag representations and international calling codes.

Features #

  • Flag Representation: Displays country flags using emojis or generated via Unicode for web and native platforms.
  • Search Functionality: Allows users to search for countries within the dropdown.
  • Customizable Display: Choose to display only flags with calling codes or include country names.
  • Responsive Design: Optimized for both mobile and web platforms.
  • Extensive Country List: Includes a comprehensive list of countries with ISO codes and calling codes.

Installation #

Add all_country_code to your project's pubspec.yaml file:

dependencies:
  all_country_code:
    git:
      url: https://github.com/loqmanali/all_code_picker.git
      ref: main

Or, if published on pub.dev, add #

dependencies:
  all_country_code: ^1.0.0

Then, run flutter pub get to install the package #

Usage #

Import the package in your Dart file:

import 'package:all_country_code/all_country_code.dart';

Use the CustomCountryDropdown widget within your widget tree #

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Country Code Picker Example',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Country Code Picker'),
        ),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: CustomCountryDropdown(
              filteredCountries: countries, // Use your filtered logic if any
              selectedCountry: 'US', // ISO code of the initially selected country
              onSelected: (isoCode) {
                // Handle country selection
                print('Selected Country ISO Code: $isoCode');
              },
              showCountryName: true, // Set to false to show only flag and calling code
              hintText: 'Select your country',
            ),
          ),
        ),
      ),
    );
  }
}

Example #

An example app is provided in the example directory. To run it:

  1. Navigate to the example directory:
cd all_country_code/example
  1. Run the app:
flutter run

This will launch the example application demonstrating the usage of the all_country_code package.

API Reference #

Country Class #

Represents a country with its name, ISO code, and calling code.

  • Properties:
    • name (String): The name of the country.
    • isoCode (String): The ISO 3166-1 alpha-2 code of the country.
    • callingCode (String): The international calling code.
  • Getters:
    • flag (String): Returns the flag representation based on the platform.
    • webFlag (String): Returns the flag emoji for web platforms.
    • nativeFlag (String): Generates the flag emoji for native platforms.
  • Static Methods:
    • fromCountryCode(String countryCode) -> String?: Returns the flag emoji for the given country code or null if not found.

CustomCountryDropdown Widget #

A customizable dropdown widget for selecting countries.

  • Properties:
    • filteredCountries (List<Country>): The list of countries to display.
    • selectedCountry (String?): The ISO code of the initially selected country.
    • onSelected (Function(String)): Callback when a country is selected.
    • showCountryName (bool): Whether to display the country name alongside the flag and calling code. Defaults to false.
    • hintText (String): The hint text to display when no country is selected. Defaults to 'Select Country'.

Contributing #

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

License #

This project is licensed under the MIT License. See the LICENSE file for details.

1
likes
150
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter package for country code picker with search and filter functionality.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on all_country_code