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

A beautiful, customizable country picker with search, multi-language support, phone codes, and great performance. Find countries even with typos, partial names.

Country Search #

A beautiful and customizable country picker widget with multi-language support and phone codes. Find countries even with typos and misspellings.

Country Picker Demo

📦 Package Size & Performance #

Package Size: ~113KB (source code, 19 languages)

Search Performance:

  • Algorithm: Optimized single-pass search with early exit
  • Speed: ~110 microseconds per query (4.7x faster than previous version)
  • Lightweight components instead of heavy Material widgets

✨ Features #

  • 🌍 246 Countries with flags, ISO codes, and phone codes
  • 🌐 Multi-language Support - 19 languages including English, Spanish, French, German, Italian, Japanese, Korean, Portuguese, Russian, Chinese, Arabic, Hindi, Indonesian, Polish, Turkish, Ukrainian, Vietnamese, Thai
  • 🔍 Smart Search by country name, code, or phone code
  • 🔤 Fuzzy Search - find countries even with typos and misspellings
  • Lightning Fast Search - 4.7x faster than previous versions
  • 📞 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
  • 📱 Weak Device Optimized - minimalist UI for smooth performance on low-end devices

✅ Works immediately without any setup! The widget uses English by default.

The widget includes intelligent fuzzy search that helps users find countries even when they make typos or misspellings. The search uses a 4-level priority system:

  1. Exact matches - perfect matches for country name, code, or phone code
  2. Starts with - query is the beginning of country name, code, or phone code
  3. Contains - query is contained within country name, code, or phone code
  4. Fuzzy search - finds countries even with typos using Levenshtein distance algorithm

Examples of fuzzy search:

  • "germny" → finds "Germany"
  • "japn" → finds "Japan"
  • "united sttes" → finds "United States"

Demo

Demo with Chinese Language

📦 Installation #

dependencies:
  country_search: ^2.6.0

🚀 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})');
  },
  showPhoneCodes: true, // Show phone codes (default)
)

Run the Example #

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

cd country_search/example
flutter run

The example demonstrates:

  • ✅ Multi-language support (19 languages)
  • ✅ Country search by name, code, and phone code
  • ✅ Beautiful dark theme UI
  • ✅ Responsive design for all screen sizes
  • ✅ Optimized performance for weak devices

🔧 Customization #

Show/Hide Phone Codes #

Control whether phone codes are displayed in the country list:

// Show phone codes (default)
CountryPicker(
  selectedCountry: selectedCountry,
  onCountrySelected: (Country country) {
    setState(() {
      selectedCountry = country;
    });
  },
  showPhoneCodes: true, // Default behavior
)

Customize Colors & Border Radius #

Easily customize the widget colors for different themes:

// Dark theme (default)
CountryPicker(
  selectedCountry: selectedCountry,
  onCountrySelected: (Country country) {
    setState(() {
      selectedCountry = country;
    });
  },
)

// Light theme with custom colors
CountryPicker(
  selectedCountry: selectedCountry,
  onCountrySelected: (Country country) {
    setState(() {
      selectedCountry = country;
    });
  },
  // Modal window colors (when picker is opened):
  backgroundColor: Colors.white,        // Background of the modal window
  headerColor: Colors.grey.shade100,   // Header background color
  cursorColor: Colors.blue,            // Search field cursor color
  
  // Button colors (the widget itself):
  searchFieldColor: Colors.grey.shade50,      // Button background color
  searchFieldBorderColor: Colors.grey.shade300, // Button border color
  textColor: Colors.black87,                  // Main text color in button
  hintTextColor: Colors.grey.shade600,        // Hint text and country code color
  accentColor: Colors.blue,                   // Phone code color
  hoverColor: Colors.grey.shade200,           // Color when hovering over countries in list
  borderRadius: 12.0,                         // Border radius for all rounded elements
)

Multi-Language Support #

The widget automatically detects the language from your app's locale. For multi-language support, add delegates to your MaterialApp:

⚠️ Note: If you want to use Flutter's standard localization delegates (GlobalMaterialLocalizations.delegate, etc.), add flutter_localizations to your dependencies:

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

⚠️ Important: Set the locale parameter to specify your app's language. Without it, the widget will use the device's system language.

How it works:

  • With locale: Uses your app's language
  • Without locale: Uses device system language
  • Unsupported language: Falls back to English
// If you don't have localization yet:
import 'package:flutter_localizations/flutter_localizations.dart';

MaterialApp(
  locale: const Locale('de'), // Set your app's language
  localizationsDelegates: [
    CountryLocalizations.delegate, // Our delegate
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
  ],
  supportedLocales: [
    const Locale('en'),
    const Locale('de'),
    const Locale('ru'),
    // Add your app's supported languages
  ],
)

// If you already have localization, add our delegate:
MaterialApp(
  locale: const Locale('de'), // Set your app's language
  localizationsDelegates: [
    // Your existing delegates
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    // Add our delegate
    CountryLocalizations.delegate,
  ],
  supportedLocales: [
    // Your existing locales
    const Locale('en'),
    const Locale('de')
  ],
)

Remove Unused Languages #

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

rm lib/src/flutter_country_picker/localizations/country_localizations_es.dart

Then update these files:

1. Main localization file (lib/src/flutter_country_picker/localizations/country_localizations.dart):

  • Remove import: import 'country_localizations_es.dart';
  • Remove from supportedLocales: Locale('es')
  • Remove from isSupported: 'es'
  • Remove case from lookupCountryLocalizations: case 'es': return CountryLocalizationsEs();

2. Main package file (lib/country_search.dart):

  • Remove export: export 'src/flutter_country_picker/localizations/country_localizations_es.dart';

⚠️ Important: If you don't update all these files, you'll get compilation errors because the code will try to import and reference deleted language files.

🌍 Supported Languages #

  • 🇺🇸 English
  • 🇷🇺 Russian
  • 🇪🇸 Spanish
  • 🇫🇷 French
  • 🇩🇪 German
  • 🇮🇹 Italian
  • 🇯🇵 Japanese
  • 🇰🇷 Korean
  • 🇵🇹 Portuguese
  • 🇨🇳 Chinese
  • 🇸🇦 Arabic
  • 🇮🇳 Hindi
  • 🇮🇩 Indonesian
  • 🇵🇱 Polish
  • 🇹🇷 Turkish
  • 🇺🇦 Ukrainian
  • 🇻🇳 Vietnamese
  • 🇹🇭 Thai

📝 License #

MIT License - see LICENSE file.

👨‍💻 Author #

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

☕ Support #

If you find this package helpful, consider buying me a coffee! ☕

ko-fi

1
likes
0
points
46
downloads

Publisher

verified publisherworldin.net

Weekly Downloads

A beautiful, customizable country picker with search, multi-language support, phone codes, and great performance. Find countries even with typos, partial names.

Repository (GitHub)
View/report issues

Topics

#flags #country #picke #search #phone-codes

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, flutter_localizations

More

Packages that depend on country_search