cupertino_country_picker 1.0.0
cupertino_country_picker: ^1.0.0 copied to clipboard
A beautifully designed iOS-style country picker for Flutter apps. Easily integrate a Cupertino-style country selector with search functionality, flags, dial codes, and a smooth user experience. Perfec [...]
🌍 Cupertino Country Picker #
A beautiful, customizable iOS-style country picker built with Flutter's Cupertino design system. Easily select countries with flags, calling codes, and search functionality. Perfect for apps that require region selection or phone number inputs.
[]
Loading preview... if it doesn't show, click here
✨ Features #
✅ iOS-style modal bottom sheet picker
✅ Search countries by name or calling code
✅ Built-in country list with flags, codes, and calling codes
✅ Easily retrieve countries using utility methods
✅ Display flag images easily using CountryHelper.packageName
CountryHelper.getByCountryCode('IN'); // 🇮🇳 India
CountryHelper.getByName('Germany'); // 🇩🇪 Germany
CountryHelper.getByCallingCode('+44'); // 🇬🇧 United Kingdom
CountryHelper.getListByQuery('can'); // 🇨🇦 Canada, 🇨🇻 Cape Verde, etc.
🛠 Installation #
Add the package in your pubspec.yaml:
dependencies:
cupertino_country_picker: ^1.0.0
Run:
flutter pub get
🚀 How to Use #
1. Show the Country Picker #
Call the showCupertinoCountryPicker() function anywhere in your app:
import 'package:cupertino_country_picker/cupertino_country_picker.dart';
ElevatedButton(
onPressed: () {
showCupertinoCountryPicker(
context: context,
onCountryPicked: (CountryModel country) {
print('Selected Country: \${country.name}');
},
);
},
child: Text('Pick Country'),
);
🖼 Output: #
A modal bottom sheet appears with a search bar, list of countries, flags, and calling codes.
🧠 Utility Methods #
You can use CountryHelper to get country data programmatically.
🔹 Get by Country Code #
final country = CountryHelper.getByCountryCode('US');
print(country?.name); // United States
🔹 Get by Country Name #
final country = CountryHelper.getByName('Japan');
print(country?.callingCode); // +81
🔹 Get by Calling Code #
final country = CountryHelper.getByCallingCode('+49');
print(country?.name); // Germany
🔹 Search Country by Query #
final results = CountryHelper.getListByQuery('in');
results.forEach((country) => print(country.name));
💡 Example Use Case #
String? _selectedCountry;
void _pickCountry(BuildContext context) {
showCupertinoCountryPicker(
context: context,
onCountryPicked: (country) {
setState(() {
_selectedCountry = '\${country.flag} \${country.name} (\${country.callingCode})';
});
},
);
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Text(_selectedCountry ?? 'No country selected'),
ElevatedButton(
onPressed: () => _pickCountry(context),
child: Text('Pick Country'),
)
],
);
}
🖼 Displaying Flag Images #
To display country flag images in your UI, you can use the CountryHelper.packageName with the Image.asset() widget:
final country = CountryHelper.getByCountryCode('IN');
if (country != null) {
Image.asset(
country.flag,
package: CountryHelper.packageName,
width: 32,
height: 20,
);
}
📚 Full Example #
Check the example directory for a working demo.
🧑💻 Contributing #
Feel free to open issues or pull requests to improve this package.
📝 License #
This project is licensed under the MIT License — free to use and distribute. No restrictions, just give credit.