country_search 2.0.3 copy "country_search: ^2.0.3" to clipboard
country_search: ^2.0.3 copied to clipboard

A beautiful and customizable country picker widget for Flutter with multi-language support, phone codes, and smart search functionality.

Country Search #

A beautiful and customizable country picker widget for Flutter with multi-language support and phone codes.

๐Ÿ“ฆ Package Size: 96KB - Zero external dependencies

โœจ Features #

  • ๐ŸŒ 246 Countries with flags, ISO codes, and phone codes
  • ๐ŸŒ Multi-language Support - English, Spanish, French, German, Portuguese, Russian
  • ๐Ÿ” Smart Search by country name, code, or phone code
  • ๐Ÿ“ž Phone Codes - Complete international dialing codes
  • ๐ŸŽจ Adaptive Design for mobile, tablet and desktop
  • โšก Lightweight - only Flutter SDK
  • ๐Ÿ”ง Highly Customizable - easily disable unwanted features
  • ๐ŸŒ Cross-Platform - works on mobile, web, and desktop

๐Ÿ“ฑ Screenshots #

Country Search Demo #

Demo

๐Ÿ“ฆ Installation #

dependencies:
  country_search: ^2.0.2

๐Ÿš€ Usage #

Basic Usage #

import 'package:country_search/country_search.dart';

CountryPicker(
  selectedCountry: selectedCountry,
  onCountrySelected: (Country country) {
    setState(() {
      selectedCountry = country;
    });
    debugPrint('Selected: ${country.flag} ${country.code} (${country.phoneCode})');
  },
)

Run the Example #

To see the widget in action, run the example app:

cd example
flutter run

Localization Setup #

MaterialApp(
  localizationsDelegates: [
    CountryLocalizations.delegate,
    // ... other delegates
  ],
  supportedLocales: [
    const Locale('en'),
    const Locale('ru'),
    // ... other languages
  ],
)

๐Ÿ“š API #

CountryPicker #

Parameter Type Description
selectedCountry Country? Selected country
onCountrySelected Function(Country) Callback on selection
labelText String? Custom label text
hintText String? Custom hint text

Country #

class Country {
  final String code;      // ISO code (e.g., 'US', 'RU')
  final String flag;      // Country flag (e.g., '๐Ÿ‡บ๐Ÿ‡ธ', '๐Ÿ‡ท๐Ÿ‡บ')
  final String phoneCode; // Phone code (e.g., '+1', '+7')
}

Country Search #

// Search by code
Country? country = CountryData.getCountryByCode('US');

// Search by phone code
Country? country = CountryData.getCountryByPhoneCode('+1');

// Search by name, code, or phone code
List<Country> results = CountryData.searchCountries(
  'russia',
  (code) => CountryLocalizations.of(context).getCountryName(code)
);

// Search by phone code only
List<Country> results = CountryData.searchByPhoneCode('+1');

๐Ÿ”ง Customization & Feature Control #

Disable Phone Codes (if not needed) #

If you don't need phone codes, you can easily ignore them:

// Just ignore the phoneCode field
CountryPicker(
  selectedCountry: selectedCountry,
  onCountrySelected: (Country country) {
    setState(() {
      selectedCountry = country;
    });
    // Only use code and flag
    debugPrint('Selected: ${country.flag} ${country.code}');
  },
)

Remove Unused Languages #

To reduce package size, remove language files you don't need:

# Remove unused language files
rm lib/src/flutter_country_picker/localizations/country_localizations_es.dart
rm lib/src/flutter_country_picker/localizations/country_localizations_fr.dart
rm lib/src/flutter_country_picker/localizations/country_localizations_ru.dart

Then update country_localizations.dart:

CountryLocalizations lookupCountryLocalizations(Locale locale) {
  switch (locale.languageCode) {
    case 'en':
      return CountryLocalizationsEn();
    // Remove cases for deleted languages
    // case 'es': return CountryLocalizationsEs();
    // case 'fr': return CountryLocalizationsFr();
    // case 'ru': return CountryLocalizationsRu();
  }
  return CountryLocalizationsEn(); // Fallback to English
}

Custom Country List #

Create your own country list with only needed countries:

// Custom country list
final myCountries = [
  Country(code: 'US', flag: '๐Ÿ‡บ๐Ÿ‡ธ', phoneCode: '+1'),
  Country(code: 'CA', flag: '๐Ÿ‡จ๐Ÿ‡ฆ', phoneCode: '+1'),
  Country(code: 'GB', flag: '๐Ÿ‡ฌ๐Ÿ‡ง', phoneCode: '+44'),
  // ... only countries you need
];

// Use in your custom picker
List<Country> filteredCountries = myCountries.where((country) => 
  country.code.toLowerCase().contains(query.toLowerCase())
).toList();

Disable Search Functionality #

If you don't need search, create a simple picker:

// Simple country list without search
ListView.builder(
  itemCount: CountryData.countries.length,
  itemBuilder: (context, index) {
    final country = CountryData.countries[index];
    return ListTile(
      leading: Text(country.flag),
      title: Text(CountryLocalizations.of(context).getCountryName(country.code)),
      subtitle: Text(country.code),
      onTap: () => onCountrySelected(country),
    );
  },
)

Custom Display Format #

Control how countries are displayed:

// Custom display without phone codes
ListTile(
  leading: Text(country.flag),
  title: Text(countryName),
  subtitle: Text(country.code), // Only code, no phone
  onTap: () => onCountrySelected(country),
)

// Custom display with only phone codes
ListTile(
  leading: Text(country.flag),
  title: Text(countryName),
  subtitle: Text(country.phoneCode), // Only phone code
  onTap: () => onCountrySelected(country),
)

๐ŸŒ Supported Languages #

  • ๐Ÿ‡บ๐Ÿ‡ธ English - "Select Country", "Search country..."
  • ๐Ÿ‡ท๐Ÿ‡บ Russian - "ะ’ั‹ะฑะตั€ะธั‚ะต ัั‚ั€ะฐะฝัƒ", "ะŸะพะธัะบ ัั‚ั€ะฐะฝั‹..."
  • ๐Ÿ‡ช๐Ÿ‡ธ Spanish - "Seleccionar paรญs", "Buscar paรญs..."
  • ๐Ÿ‡ซ๐Ÿ‡ท French - "Sรฉlectionner un pays", "Rechercher un pays..."
  • ๐Ÿ‡ฉ๐Ÿ‡ช German - "Land auswรคhlen", "Land suchen..."
  • ๐Ÿ‡ต๐Ÿ‡น Portuguese - "Selecionar paรญs", "Pesquisar paรญs..."

๐Ÿงช Testing #

flutter test

๐Ÿ“ License #

MIT License - see LICENSE file.

๐Ÿ‘จโ€๐Ÿ’ป Author #

Stanislav Bozhko
Email: [email protected]
GitHub: @stanislavworldin

1
likes
0
points
53
downloads

Publisher

verified publisherworldin.net

Weekly Downloads

A beautiful and customizable country picker widget for Flutter with multi-language support, phone codes, and smart search functionality.

Repository (GitHub)
View/report issues

Topics

#flags #country #picker #search #phone-codes

Documentation

Documentation

License

unknown (license)

Dependencies

flutter

More

Packages that depend on country_search