country_search 2.1.1 copy "country_search: ^2.1.1" to clipboard
country_search: ^2.1.1 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 (English by default) #

import 'package:country_search/country_search.dart';

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

βœ… Works immediately without any setup! The widget uses English by default.

Multi-Language Support (Optional) #

For multi-language support, add delegates to your MaterialApp:

// If you don't have delegates yet:
MaterialApp(
  localizationsDelegates: CountrySearchDelegates.allDelegates,
  supportedLocales: CountrySearchDelegates.supportedLocales,
  // ... rest of your app
)

// If you already have delegates, add ours:
MaterialApp(
  localizationsDelegates: [
    // Your existing delegates
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    // Add our delegate
    CountryLocalizations.delegate,
  ],
  supportedLocales: [
    // Your existing locales
    const Locale('en'),
    const Locale('de')
  ],
)

Run the Example #

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

cd example
flutter run

The example demonstrates:

  • βœ… Multi-language support (6 languages)
  • βœ… Country search by name, code, and phone code
  • βœ… Beautiful dark theme UI
  • βœ… Responsive design for all screen sizes

Localization Setup #

MaterialApp(
  localizationsDelegates: CountrySearchDelegates.allDelegates,
  supportedLocales: CountrySearchDelegates.supportedLocales,
)

πŸ“š 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')
}

Search Examples #

// 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)
);

πŸ”§ Customization #

Multi-Language Support (Optional) #

The widget works with English by default. For multi-language support, add delegates to your MaterialApp:

MaterialApp(
  localizationsDelegates: CountrySearchDelegates.allDelegates,
  supportedLocales: CountrySearchDelegates.supportedLocales,
  // ... rest of your app
)

Disable Phone Codes (Optional) #

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

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 Display Format #

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

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

If you don't need search functionality, 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),
    );
  },
)

🌍 Supported Languages #

  • πŸ‡ΊπŸ‡Έ English
  • πŸ‡·πŸ‡Ί Russian
  • πŸ‡ͺπŸ‡Έ Spanish
  • πŸ‡«πŸ‡· French
  • πŸ‡©πŸ‡ͺ German
  • πŸ‡΅πŸ‡Ή Portuguese

πŸ§ͺ Testing #

flutter test

πŸ“ License #

MIT License - see LICENSE file.

πŸ‘¨β€πŸ’» Author #

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

1
likes
0
points
46
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, flutter_localizations

More

Packages that depend on country_search