country_search 2.0.3
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 #

๐ฆ 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